< html:link /> html tag
Previous | Home | Next |
The struts link tag is a render of html <a> anchor element.This tag is used to generate an HTML hyperlink.
If a hyperlink to the specified URL than the URL for this hyperlink is calculated based on which of the following attributes...
- forward :- This is used the name of a global ActionForward to be looked up and will receive control of the forwarded request.
- action :- This is used the name of a Action to be looked up.The name of the Action should be a defined Action name from the struts-config.xml file..
- href :- This is used to create a link to another document.The URL to which this hyperlink will transfer control if activated.
- page :- This is used to a module-relative URI and specifies an application-relative path of the image source which is used by input tag.
The struts link tag have following attributes:-
- accesskey :-This keyboard character used to move focus immediately to this element.
- anchor :-This is used to to be added to the generated hyperlink.
- bundle :-The servlet context attributes key for the MessageResources instance to use. If not specified, defaults to the application resources configured for our action servlet.
- dir :-The direction for weak/neutral text for this element.
- indexId :- the indexed parameter can be specified a jsp scripting element.
- indexed :-If true then indexed parameter with name from indexId attribute will be added to the query string.
- linkName :- The value specified here will render a "name" element in the generated anchor tag.
The Following are many other attributes which we can use :
- name
- module
- lang
- onblur
- onclick
- ondblclick
- onfocus
- onkeydown
- onkeypress
- onkeyup
- onmousedown
- onmousemove
- onmouseout
- onmouseover
- onmouseup
- page
- paramId
- paramName
- paramProperty
- paramScope
- property
- scope
- style
- styleClass
- styleId
- tabindex
- target
- title
- titleKey
Directory Structure of LinkTagExample in Struts 1.3 Using MyEclipse IDEindex.jsp<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <html> <head> <title><bean:message key="label.title"/></title> </head> <body> <h3><bean:message key="label.header"/></h3> <h4><html:link action="/linkAction">Struts Link Tag Example</html:link></h4> </body> </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/> <global-exceptions /> <global-forwards /> <action-mappings > <action path="/linkAction" type="org.r4r.struts.LinkAction"> <forward name="success" path="/success.jsp"/> </action> </action-mappings> <message-resources parameter="org.r4r.struts.ApplicationResources" /> </struts-config>LinkAction.javapackage 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 LinkAction extends Action { public ActionForward execute(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception{ return mapping.findForward("success"); } }ApplicationResources.properties# Resources for parameter 'org.r4r.struts.ApplicationResources' # Project Struts1.3_LinkTagExample #label message label.title=Struts html:link tag example label.header=Struts html:link tag examplesuccess.jsp<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <html> <head> <title><bean:message key="label.title"/></title> </head> <body> <h3><bean:message key="label.header"/></h3> <h4>This output is generated by link tag example in struts 1.3</h4> </body> </html>Output
Previous | Home | Next |