Home » Enterprise Java » jstl » Get Request Parameter with JSTL in JSP Page

About Ilias Tsagklis

Ilias Tsagklis
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

Get Request Parameter with JSTL in JSP Page

With this example we are going to demonstrate how to get Request Parameter with JSTL in a JSP page. JavaServer Pages Standard Tag Library (JSTL) encapsulates as simple tags the core functionality common to many Web applications. JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags. In short, to get Request Parameter with JSTL in a JSP page you should:

  • Create a jsp page that contains the <%code fragment%> scriptlet. It can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language.
  • Include JSTL Core library in your JSP page, using the <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> syntax.
  • Use the <c:choose> tag, that works like a Java switch statement in that it lets you choose between a number of alternatives. It uses <c:when> tag, with an attribute named test that evaluates a condition. It also uses <c:otherwise> to perform the default clause.

Let’s take a look at the code snippet that follows:  

GetRequestParameterJSTL.jsp

<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/c-rt.tld" prefix="c-rt" %>

<html>

<head>
	<title>Java Code Geeks Snippets - Get Request Parameter with JSTL in JSP Page</title>
</head>

<body>
	
	<%-- if/else condition --%>
	<c-rt:choose>
	    <c-rt:when test="${empty param.myname}">
	
  Please provide your name </br>
	    </c-rt:when>
	    <c-rt:otherwise>
	
 	Welcome <c-rt:out value="${param.myname}" />.
	    </c-rt:otherwise>
	</c-rt:choose>
	
</body>

URL:

http://localhost:8080/jcgsnippets/GetRequestParameterJSTL.jsp?myname=ilias

Output:

Welcome ilias.

  
This was an example of how to get Request Parameter with JSTL in a JSP page in Java.

(No Ratings Yet)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar
  Subscribe  
Notify of