• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pass parameters from one jsp page to other jsp page

 
Manas Saxena
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ganesh Shirsat
Ranch Hand
Posts: 33
Google Web Toolkit Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it doesn't matter to you that you're following poor practices?
 
Chiranjib Bhattacharjee
Greenhorn
Posts: 12
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Manas Saxena
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 7
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic