tags:

views:

1047

answers:

1

How can I pass Parameters between JSP pages using pure Java Code?

I.e. I don't want to use codes like the following:

<jsp:include page="<%=fileName%>" flush="true">
                        <jsp:param name="txtUsername" value="<%=_USERNAME_%>" />
                        <jsp:param name="txtName" value="<%=name%>" />
                        <jsp:param name="txtPassword" value="<%=_PASSWORD_%>" />
                </jsp:include>

I need a pure Java code.

+2  A: 

How about:

<% request.setAttribute("foo", "bar"); %>
<jsp:include page="<%=fileName%>" flush="true" />

And the corresponding usage in the included file:

<%= request.getAttribute("foo") %>

EDIT: Typo fixed

mkoeller
Would this work in case of Redirecting pages with parameters?
@JMSA: This solution does only work for server-side forwards, like includes. To handle redirects, you might add the attributes to the session not the request. But then the attributes will stay as long as the session is active.
mkoeller