Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

retrieving values from url rewritting in jsp

 
kavita mehra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to get the values passed by url rewritting from the same jsp?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What values? The parameters? The session id?
 
kavita mehra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i mean the parameters......which we pass from the url.....
<a href="/airways1/bank.jsp?flightid=<%=f1%>"> <%=x %></a>
now i would like the value of flightid to be retrieved again on this jsp...n i have used request.getparameter().it should work according to me.but its not getting any value when i click the hyperlink.....when i display it on the console window it is showing a null value.that means it is not passing the value.or have i made a mistake.please help and suggest.
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you doing something like this ::

Suppose your url is www.bookmyflight.com?flightid=12&name=ujjwal



 
kavita mehra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int flightid=Integer.parseInt(request.getParameter("flightid").toString());

will this statement give a value if called on the same jsp....or will we have to retreive it from another jsp...
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kavita mehra wrote: will this statement give a value if called on the same jsp....or will we have to retreive it from another jsp...


what you mean by same jsp? Where ever the request is being sent to (JSP/Servlet etc..) would be able to use that. If you post your code it'll be easier to answer the questions on that.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


int flightid=Integer.parseInt(request.getParameter("flightid").toString());

will this statement give a value if called on the same jsp....or will we have to retreive it from another jsp...


Definitely a null pointer exception or numberformat exception on first run..
 
kavita mehra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes sir it is showing a null pointer exception.......how do i retrieve the value....sent by the hyperlink on the same jsp.i.e the jsp in which im using the hyperlink is the one which is being called.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kavita mehra wrote:yes sir it is showing a null pointer exception.......how do i retrieve the value....sent by the hyperlink on the same jsp.i.e the jsp in which im using the hyperlink is the one which is being called.


Can you just elaborate this a bit perhaps using your code (that would be really easy to answer) - How you call the jsp etc.. ?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kavita mehra wrote:yes sir it is showing a null pointer exception.......how do i retrieve the value....sent by the hyperlink on the same jsp.i.e the jsp in which im using the hyperlink is the one which is being called.


check if request.getParameter("flightid") is null ? if yes, you cant do much..just to wait for someone to click the link for your second request with data for flight id..

But Still this question remains same , why do you want to do that in same jsp? and exactly what you want to achieve ? if you elaborate , perhaps there are many other ways than this
 
kavita mehra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to display an image on the same page using an hyperlink..


i m using the value retreived by the hyperlink to be send to a function defined in the bean.java..



the function in the bean..



then i m using getRs1() method to retrive path of the image through database..



and then using expression to display the image..



but i m unable to retreive the value using request.getParameter(). it is showin null value in the Tomcat console.. please help.. i m confused..
 
Keerthi Sagar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kavitha,
Try with location.href

Regards,
Y. Keerthi Sagar.
 
kavita mehra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please explain what exactly you want me to do..? i am not familiar with location.href...
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Are these above 2 statements available in same JSP ? why do you want to send "n" as request parameter and get the same in the next line and use it. this is total of mess of design and not a way to use JSP.

you miss basics here
1) When this jsp is executed , line1 is translated and value of n (if there is one) is rendered as html
2) "request" is the ServletRequest object containing request information that is sent when you call this jsp. (line2)
3) you should note that <%=n %> is executed in the server itself before sent to the browser. so when it reaches the client browser , it looks like this

4) so now you should understand that line 1 and 2 are executed in server end . Right click and see view source and check what is the value and see it yourself.



  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What a mess. This is exactly the reason that putting scriptlets in a JSP went out in 2002. Perhaps this article can help you understand how web apps can be structured more cleanly and possibly help you in the future.
 
kavita mehra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.. so you are saying that the hyperlink is executed in the server before it reaches the client browser.. i got that.. thanks..

but is it possible if i place the request.getParameter() in a condition such that it is called only after a hyperlink is pressed.. Then can i retreive the value passed by hyperlink through request.getparameter()...?? please explain
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kavita mehra wrote:
but is it possible if i place the request.getParameter() in a condition such that it is called only after a hyperlink is pressed.. Then can i retreive the value passed by hyperlink through request.getparameter()...?? please explain



NO !! and even if there are shortcuts.. that would be jsp "crap" which is useless .
 
kavita mehra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got it.. it can be done.. but yes its messy.. thanks for putting me right..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic