JSTL Core Tag param Example

JSTL Core Tag param Example


Posted in : Java Posted on : April 2, 2012 at 7:20 PM Comments : [ 0 ]

In this tutorial you will learn about the JSTL core URL management param tag.

JSTL Core Tag param Example

In this tutorial you will learn about the JSTL core URL management param tag.

The param tag is used to add a parameter to the url. Using param tag you can provide the additional information to the url. This tag can be used with the <c:import>, <c:url>, <c:redirect>

Attributes of param tag :

  • name : This attribute specifies the name of a parameter.
  • value : This attribute specifies the value of a parameter.

After embedding the specified param tag an url will be passed on a request made as "requestedURL?paramName1=value1;paramName2=value2....."

Example :

Here I have given a simple example that will demonstrate you how to use the <c:param> tag in jsp. In this example I have created a jsp page named JstlCoreTagParamExample.jsp into which I have used the <c:url> and the <c:param> tag to give the parameter value to make the url with the help of these parameter values. And then created an another jsp page named a.jsp. On this page I have tried to fetch the value of the parameters that I had been provided using <c:param> tag in the page JstlCoreTagParamExample.jsp. Next I have created a hyperlink using these url on this page onto which clicking a http://localhost:8080/jspExamples/a.jsp?name1=Dev&name2=Manuals page will be opened. Here the values of parameters will also shown.

JstlCoreTagParamExample.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>JSTL Example</title>
</head>
<body>
<h3>JSTL Core Tag param Example.</h3>
<c:url value="a.jsp" var="myURL">
<c:param name="name1" value="Dev"/>
<c:param name="name2" value="Manuals"/>
</c:url>
<a href="${myURL}">a.jsp</a>
<p>Generated URL = ${myURL}</p>
</body>
</html>

a.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p>Value of parameter1 = ${param.name1}</p>
<p>Value of parameter2 = ${param.name2}</p>
</body>
</html>

How to run this example

Here I am using an IDE Eclipse so I am giving the process of executing this example in perspective of Eclipse. Before executing this example you will have needed to add the following jar files :

  • jstl.jar
  • standard.jar

After adding of these jar files you may execute your program in the following ways :

  • Select JstlCoreTagParamExample.jsp file of your project in Project Explorer -> RightClick -> Run As -> Run On Server -> Choose your server -> Finish.
  • On the Eclipse Editor go to your JstlCoreTagParamExample.jsp -> RightClick -> Run As -> Run On Server -> Choose your server -> Finish.
  • Go to Run button look at the toolbar in green color and click -> Choose your server -> Finish.
  • A simplest way to execute the example in Eclipse is to use the CTRL+F11 key -> Run On Server -> Choose your server -> Finish

NOTE : In all of the above execution processes you may start the server first and stop the server each time after the execution if not, each time you will may prompted to a dialog box to Restart the server in Eclipse.

Output :

When the execution process will be completed successfully an output will be displayed on the browser as :

1. When you will execute the JstlCoreTagParamExample.jsp output will be as follows :

2. When you will click on the hyperlink a.jsp a new page will be open and the values of parameter will displayed.

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics