In the below code i m trying to send my request attribute from req.jsp page to retr.jsp.

i would like to know if we can pass request attributes from one jsp page to other jsp page


the below is my req.jsp

<html>
<head>
hey i m page 1
</head>
<body>
<% request.setAttribute("info from page1", info); %>
<% RequestDispatcher dispatch=request.getRequestDispatcher("/retr.jsp");
dispatch.forward(request,response);
%>
</body>
</html>

this is my retr.jsp

<html>
<head>
i m gettin request from page1
</head>
<body>
<%=request.getAttribute("info")%>
</body>
</html>

Recommended Answers

All 7 Replies

I haven't tried that code. You need to check it yourself.

But I would suggest this, if you want to have more chances of succeeding.

<% request.setAttribute("[B]info[/B]", "info from page1"); %>

....

<%=request.getAttribute("[B]info[/B]")%>

hey it will work in one jsp page..

but i want request attributes to be passed to another jsp page..is it possible??

I didn't mean that you put both lines in the same file.
One line goes to one file and the other to the other.
Try your code to see if it works, with the suggestion I gave you.

i have tried it in diff pages itself

wen i try to open this page

http://localhost:8080/onejsp/retr.jsp

i get output lik this

i m gettin request from page1 null

i couldnt retrieve from req.jsp page in retr.jsp page

How are you suppose to retrieve the value if you don't execute the page req first. This is where you set the attribute.

You say "i couldnt retrieve from req.jsp page in retr.jsp page "
Of course you didn't . When you opened the retr, you had't put anything in the request. Did you call the req.jsp in order to get the request from?

Then I guess it cannot be done that way. You don't need to use that code inside a jsp. You usually do that in a servlet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.