URL tag example in struts2.0 framework

URL tag example in struts2.0 framework

Previous Home Next

 

The struts2.0 framework tag library provide url tag to provide the actual path in anchor tag ,image tag etc. Through this tag send request ti server in specified url.
<s:url value="  "/>

The struts 2.0 framework provide following url tag,
<s:url value="/images/a.jpg"/>
 
Directory Structure of <s:url> tag Example in Struts 2.0 Using MyEclipse IDE



index.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>

<h1>URL tag example in Struts2 Framework</h1>
 

<img src="<s:url value="/images/pic27.gif"/>" /><br/><br/>

<a href="<s:url value="http://www.google.com"  />" >Google</a><br/><br/>

<s:url action="urlTagAction.action" >
    <s:param name="id">123</s:param>
</s:url><br/><br/>

<s:url action="urlTagAction.action" var="urlTag" ><br/><br/>
    <s:param name="name">R4R</s:param>
</s:url>
<a href="<s:property value="#urlTag" />" >URL Tag Action Through Property Tag</a>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  
  <filter>
  <filter-name>f1</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>f1</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration
2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="demo" extends="struts-default">
<action name="" class="org.r4r.UrlTagAction">
<result name="success">/index.jsp</result>
</action>
</package>
</struts> 

UrlTagAction.java

package org.r4r;

public class UrlTagAction {
	public String execute(){
		return "success";
	}

}

Output






Previous Home Next