Pass Data from one page to another
I have a page consisting of many anchor tags and when each link is clicked an associated data has to be 开发者_运维问答sent to the target page and is to be displayed in the target page. Here is the snapshot of the code
<a href="target.html?Some%data">click1</a>
<a href="target.html?Some%other%data">click2</a>
and so on...i should be able to display Some data when i click on clik1 and Some other data when i click on click2
actual i have two jsp pages...source.jsp and target.jsp
Pass them as GET request parameters in a query string in source.jsp
:
<a href="target.jsp?data=some%20data">click1</a>
<a href="target.jsp?data=some%20other%20data">click2</a>
(note that a space is to be URL-encoded as %20
, not as %
)
And use EL ${param}
to access them in the target.jsp
:
<p>The parameter with name "data" has the value ${param.data}</p>
To prevent XSS attacks, preferably use JSTL's c:out
to redisplay user-controlled input:
<p>The parameter with name "data" has the value <c:out value="${param.data}" /></p>
See also:
- Java EE 5 tutorial - Implicit objects in EL
- JSP tag info page
精彩评论