wood burning stoves*
The moose likes Servlets and the fly likes Pass parameters from one jsp page to other jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Pass parameters from one jsp page to other jsp page" Watch "Pass parameters from one jsp page to other jsp page" New topic
Author

Pass parameters from one jsp page to other jsp page

Manas Saxena
Ranch Hand

Joined: Mar 01, 2013
Posts: 38
I need to pass a String from one jsp page(say A.jsp) to other(say B.jsp) without displaying the second page(B.jsp).
I have tried setAttribute and getAttribute but null value is received on the B.jsp. Please help
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2833
    
  11

A JSP that doesn't display sounds like it would be better implemented as a servlet. I would have A.jsp submit the String as a request parameter, probably by posting it with a form directed to a URL handled by my B servlet. The B servlet would have a doPost() method, and could do whatever it wanted to do with the String.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60739
    
  65

You'll need to explain why you are trying to do what you are trying to do. As Greg pointed out, what you are describing is not a good design. A JSP is an end point that should be rendering the view.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ganesh Shirsat
Ranch Hand

Joined: Jan 10, 2010
Posts: 32

There is some way to do this
1. Using Query parameter

Then you can read that parameter with

on the second page.

2. Using Hidden variable

3. Using Session object


These values will now be available from any jsp as long as your session is still active.

Manas Saxena
Ranch Hand

Joined: Mar 01, 2013
Posts: 38
@ganesh shirsat
Thanks for the reply but i tried all three aproaches but i am getting out as null.what do i do?
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

By "not displaying", do you mean you want to create a pop-under window or something similar?
Also we cannot help you out unless you TellTheDetails, or PostRealCode.
One possible reason could be incorrect variable name.


SCJP, SCWCD.
|Asking Good Questions|
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60739
    
  65

So it doesn't matter to you that you're following poor practices?
Chiranjib Bhattacharjee
Greenhorn

Joined: Nov 08, 2012
Posts: 12

request.setAttribute() and request.getAttribute() should solve your problem.

Pay heed to this as well:
So it doesn't matter to you that your following poor practices?


~ godspeed.
Manas Saxena
Ranch Hand

Joined: Mar 01, 2013
Posts: 38
@Bear Bibeault
I really appreciate the concern but the problem is i have been trying very hard to get the servlet running but its not working and the deadline for the project which i am preparing is just a few days away ,thats why i am trying to get the thing to work.I have definitely kept your advice in mind and will follow it after this project.
Parth Bhagat
Greenhorn

Joined: Mar 14, 2013
Posts: 7

Manas, it will be better if you explain the exact scenario so that Javaranchers can help you.

Parameter set is retrieved as null, one of the reasons could be where you have set the parameter & how you are getting it. Have you included jsp page inside another one or you don't at all want that page to be displayed? If you don't want to display it then you should use servlet for that. If servlet is not working then there must be some mistake configuring servlet in deployment descriptor or calling properly mapped servlet.

It will all be anticipated answers. Please share more detail for perfect one.
Manas Saxena
Ranch Hand

Joined: Mar 01, 2013
Posts: 38
OK got the servlet working heres the scenario and the real problem

I am making a registration page which performs ajax validation on email to check its validity and availablility(from database). The form should not be submitted on click of submit button if email id is invalid Now the problem is that my ajax call is simply displaying valid email or invalid ,and i need it to return true or false so that i could pass this value to form in order to prevent its submission.
I am unable to return any value from servlet KEEPING IN MIND THAT MY PAGE SHOULDN'T REFRESH.(i used request dispatcher but it refreshes the page so setattribute and getattribute wont work here).
heres my jsp code(reginfo.jsp)



and heres my servlet (regajax4.java)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60739
    
  65

You've already asked your Ajax question at least 3 other times, and the answer to your Ajax problem is here. Please do not spread a question across multiple posts. It just wastes everyone's time.

Also, the above code is way too much to look through. Please post an SSCCE demonstrating the issue.
Manas Saxena
Ranch Hand

Joined: Mar 01, 2013
Posts: 38
Heres the shorted code.sry am new around here i am learning from my mistakes

heres my jsp code(reginfo.jsp)



and heres my servlet (regajax4.java)
 
wood burning stoves
 
subject: Pass parameters from one jsp page to other jsp page
 
Similar Threads
flush and forward works ?
Passing values to jsp page
transfering a value from one jsp page to many jsp pages
Changing the URL when using forward or redirect...
Using jsp:useBean across JSPs