Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Create URL using tag of JSTL Core tag library 
 

Here in this example we are going to create a url according to the user's given parameter by using tag.

 

Create URL using <c:url> tag of JSTL Core tag library

                         

Here in this example we are going to create a url according to the user's given parameter by using <c:url> tag.

 

 

 

 


 

 

<C:url> : This is a member of JSTL core tag library and used to create url with some optional parameters.
Attributes of the tag <c:url>  
var  Declare a scoped variable that stores the url.
scope  Define the scope for declared variable like page or request or session or application.
value  Value attribute define a String that is used to specify a url that will process as url later.
context  We can provide context name as attribute that is prepended with the url. For this url and 
 context must start with forward slash. If url is not started with forward slash, it is assumed 
 to be a relative url, in this situation context name is unnecessary.

We have also used tag <c:param> to add parameters to the specified url. Attribute of this tag are name  that is used to provide a name to parameter and value
is used to initialize parameter of this name.

In the code given below, first we will create a web page having three text fields for name, age and sex. When user enters all these information and click on submit button then <c:url> tag calculate the url with the given paramaters and show the calculated url  in the same web page.

createUrl.jsp

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<c:url value="displayValues.jsp" var="displayURL">
	<c:param name="name" value="${param.name}" />
	<c:param name="age" value="${param.age}" />
	<c:param name="gender" value="${param.gender}" />
</c:url>
<html>
<head>
<title>c:url CoreJstl Tag</title>
</head>
<body>
<font size="4" color="green">This page takes 3 values that user entered
in the text box given <br>
below and when click on submit button shows url with given parameters.</font>
<form method="post">
<table>
	<tr>
		<td>Enter name:</td>
		<td><input type="text" name="name" /></td>
	</tr>
	<tr>
		<td>Enter age:</td>
		<td><input type="text" name="age" /></td>
	</tr>
	<tr>
		<td>Enter gender:</td>
		<td><input type="text" name="gender" /></td>
	</tr>
</table>
<input type="submit" value="submit" /></form>
<c:if test="${pageContext.request.method=='POST'}">
    Here application receives the values that you have submitted, 
    <br>and creates a URL that contains
    these values.
    <p /><strong>URL is </strong><font size="3" color="red"><c:out
		value="${displayURL}" /></font>
</c:if>
</body>
</html>

Steps to run this example :

1:  Download the zip file of code and unzip this file, you will get a folder named  'catch_exception_jstlCoreTag'.
2:  Paste this folder in 'Apache Tomcat 6.0.16-->webapps' or generally in directory 'C:\apache-tomcat-6.0.16\webapps'.
3:  Start tomcat server by click on startup.bat file in 'C:\apache-tomcat-6.0.16\bin'.
4: Open browser and type url 'http://localhost:8080/create_url_jstlCore/createUrl.jsp' or click on this link.

Output of the program

When user clicks on submit button, response will be...

Download Source Code

                         

» View all related tutorials
Related Tags: c xml library file files stl orm ant form io user sed jstl tag parameter transform this js for add

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.