Struts2.2.1 url Tag Example
Posted on: January 11, 2011 at 12:00 AM
In this tutorial, We will discuss about the URL tag in struts2.2.1This tag is used.to to create an URL and output it as a text format.

Struts2.2.1 url Tag Example

In this tutorial, We will discuss about the URL tag in struts2.2.1This tag is used.to to create an URL and output it as a text format. It?s never work by itself,but it can provides URL to other tags like <s:a> to create a hyperlink or <img> to render an image.

The following Example will shows how to implement the URL tag in the Struts2.2.1 --

First we create a JSP file named URLtag.jsp as follows.ADS_TO_REPLACE_1

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">ADS_TO_REPLACE_2

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

<html>

<head>ADS_TO_REPLACE_3

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>URL tag Example</title>

</head>ADS_TO_REPLACE_4

<body>

<ol>

<li>Image URL Here:<br>ADS_TO_REPLACE_5

<a href="http://www.roseindia.net"><img

src="<s:url value="C:\gyan struts\url tag\logo.gif" /> " height="60"

width="70" /></a></li>ADS_TO_REPLACE_6

<li>Simple URL Here:<br>

<a href="<s:url value="http://www.roseindia.net" />">RoseIndia</a></li>

<li><s:url action="URLtag.action" var="URLtag">ADS_TO_REPLACE_7

<s:param name="name">RoseIndia</s:param>

</s:url> <a href="<s:property value="#URLtag" />">URL Tag Action (via

property)</a></li>ADS_TO_REPLACE_8

<li><s:url action="URLtag.action" var="URLtag">

<s:param name="name">GyanSingh</s:param>

</s:url> <s:a href="%{URLtag}">URL Tag Action (via %)</s:a></li>ADS_TO_REPLACE_9

</ol>

</body>

</html>

The Struts mapping file Struts.xml is as follows-ADS_TO_REPLACE_10

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"ADS_TO_REPLACE_11

"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<constant name="struts.enable.DynamicMethodInvocation"ADS_TO_REPLACE_12

value="false" />

<constant name="struts.devMode" value="false" />

<constant name="struts.custom.i18n.resources"ADS_TO_REPLACE_13

value="ApplicationResources" />

<package name="default" namespace="/" extends="struts-default">

<action name="URLtag" class="roseindia.URLtag">ADS_TO_REPLACE_14

<result name="success">/URLtag.jsp</result>

</action>

</package>ADS_TO_REPLACE_15

</struts>

The action class URLtag.java is as follows.

package roseindia;

import com.opensymphony.xwork2.ActionSupport;ADS_TO_REPLACE_16

public class URLtag extends ActionSupport{

public String execute() throws Exception {

return SUCCESS;ADS_TO_REPLACE_17

}

}

This Program produces output on the basis of the URL tag  evaluation, This  give the output as-

Output:-ADS_TO_REPLACE_18

Download Select Source CodeADS_TO_REPLACE_19

Related Tags for Struts2.2.1 url Tag Example:

Advertisements

Ads

 
Advertisement null

Ads