jstl

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.

Ilias Tsagklis

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button