Access and print HTTP request query string parameters via EL in JSP page

2.3k views Asked by At

I need to pass a request parameter from one JSP to another JSP page like this:

<a href="cv.jsp?type=alaacv">alaa</a>

However, when I try to access it as below, it doesn't print anything.

<c:set var="selectedCV" value="${type}" scope="request" />
<c:out value="${selectedCV}" />

How is this caused and how can I solve it?

2

There are 2 answers

4
BalusC On BEST ANSWER

You need to access it by ${param} which is an implicit EL object referring to the request parameter map (which is actually a Map<String, String>; if you need the Map<String, String[]> for multi-valued parameters, use ${paramValues} instead).

<c:set var="selectedCV" value="${param.type}" />
<c:out value="${selectedCV}" />

The ${param.type} basically resolves to request.getParameter("type").

You can also just do as below without the need for <c:set>:

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

See also:

3
Jawa On

You need to pass the given parameter in response object to the second .jsp. How to do that depends on the servlet/framework you are using (unless the framework should somehow do it automatically).