JSTL - form data (POST GET)

Home > Search
  by

Add the following to the head of your JSP page.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

 


GET

Let's say you have a URL with a parameter such as id=12345.

www.example.com?id=12345

 

The following will print the id (12345 in this example).

<c:out value="${param.id}" />

 

Or, you can use c:set to store the value in a variable. In this example, the ID is stored in a variable called "id".

<c:set var="id" value="${param.id}" />

 

You can then print the value using this markup.

${id}

 


POST

In this example the value in the form is associated with the "username" value are is POST to example.jsp.

<form method="post" action="example.jsp">
  <input type="text" name="username">
</form>

 

On example.jsp, use the following to display the username value.

<c:out value="${param.username}" />

 

Or, you can use c:set to store the value in a variable. In this example, the ID is stored in a variable called "username".

<c:set var="username" value="${param.username}" />

 

You can then print the value using this markup.

${username}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments