< html:html /> html tag

< html:html /> html tag

Previous Home Next

 

The  tag is part of Struts HTML Tags Library.  The <html:html /> tags is used to render the top-level html element. It is top tag than all tags library (Struts HTML Tags). All tags will be inside of this tag. 
This Tag is used for extracted from the user's  current Locale object and renders an HTML element <html> with language attributes.

 It has following attribute :-

1. lang :-
We can set lang=”true/false” By default lang is false. If we set true then the lang attribute will be set to the local language stored into session of that users. If there is not a locale stored in the session then the language will be set to that specified by the current request's "AcceptLanguage"HTTP header. If there is not an AcceptLanguage" header value, the language will be set to server's default.

2. xhtml :-This xhtml attribute is by default false. The xhtml=true mean that It render to xml:lang and xmlns attributes on the generated html element. the HTML Tag library will generate output as xhtml instead of html.Synatax of this attributes <html:xhtml/> .


Directory Structure of HtmlTagExample in Struts 1.3 Using MyEclipse IDE




index.jsp

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<html:html>
<head>
<title><bean:message key="label.title"/></title>
</head>
<body>
<h3><bean:message key="label.header"/></h3>
<html:form action="/htmlAction">
<bean:message key="label.name"/>:
<html:text property="name" name="htmlForm"/><br/>
<bean:message key="label.technology"/>:
<html:text property="technology" name="htmlForm"/><br/>
<br/>
<html:submit><bean:message key="label.submit" /></html:submit>
<html:reset><bean:message key="label.reset" /></html:reset>
</html:form>
</body>
</html:html>

web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
 
<web-app>
  <display-name>Maven Struts Examples</display-name> 
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>
        org.apache.struts.action.ActionServlet
    </servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>
         /WEB-INF/struts-config.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet> 
  <servlet-mapping>
       <servlet-name>action</servlet-name>
       <url-pattern>*.do</url-pattern>
  </servlet-mapping> 
</web-app>

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
  <form-beans>
    <form-bean name="htmlForm" type="org.r4r.struts.HtmlForm"/>
  </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action path="/html" type="org.apache.struts.actions.ForwardAction" parameter="/index.jsp"/>
		<action path="/htmlAction" type="org.r4r.struts.HtmlAction" name="htmlForm" input="/index.jsp">	
         <forward name="success" path="/success.jsp"/>
		</action>
  </action-mappings>
  <message-resources parameter="org.r4r.struts.ApplicationResources" />
</struts-config>

HtmlForm.java

package org.r4r.struts;

import org.apache.struts.action.ActionForm;

@SuppressWarnings("serial")
public class HtmlForm extends ActionForm {
	private String name;
	private String technology;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getTechnology() {
		return technology;
	}
	public void setTechnology(String technology) {
		this.technology = technology;
	}
}

HtmlAction.java

package org.r4r.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class HtmlAction extends Action {
	public ActionForward execute(ActionMapping mapping,ActionForm form,
		HttpServletRequest request,HttpServletResponse response) throws Exception{
		@SuppressWarnings("unused")
		HtmlForm passwordForm=(HtmlForm)form;
		return mapping.findForward("success");
	}
}

ApplicationResources.properties

#label message
label.title=Struts html:html tag example
label.header=Struts html:html tag example
label.name = User Name 
label.technology = Technology Name
label.submit = Submit
label.reset = Reset

success.jsp

<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html:html xhtml="true">
<head>
<title><bean:message key="label.title"/></title>
<html:base/>
</head>
<body>
<h3><bean:message key="label.header"/></h3>
<h4><bean:message key="label.name"/>:-
<bean:write name="htmlForm" property="name" /></h4>
<h4><bean:message key="label.technology"/>:-
<bean:write name="htmlForm" property="technology" /></h4>
</body>
</html:html>

Output





Previous Home Next