开发者

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

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 v开发者_StackOverflow社区ar="selectedCV" value="${type}" scope="request" />
<c:out value="${selectedCV}" />

How is this caused and how can I solve it?


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:

  • How to access objects in EL expression language ${}
  • How can I retain HTML form field values in JSP after submitting form to Servlet?
  • Our EL wiki page


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜