This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes retrieving values from url rewritting in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "retrieving values from url rewritting in jsp" Watch "retrieving values from url rewritting in jsp" New topic
Author

retrieving values from url rewritting in jsp

kavita mehra
Greenhorn

Joined: Mar 14, 2009
Posts: 8
how to get the values passed by url rewritting from the same jsp?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30596
    
154

What values? The parameters? The session id?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
kavita mehra
Greenhorn

Joined: Mar 14, 2009
Posts: 8
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

Joined: Mar 28, 2007
Posts: 403
Are you doing something like this ::

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




Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
kavita mehra
Greenhorn

Joined: Mar 14, 2009
Posts: 8
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

Joined: Mar 24, 2008
Posts: 3833

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.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



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

Joined: Mar 14, 2009
Posts: 8
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

Joined: Mar 24, 2008
Posts: 3833

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

Joined: Jan 01, 2009
Posts: 874

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

Joined: Mar 14, 2009
Posts: 8
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

Joined: Apr 21, 2007
Posts: 28
Hi Kavitha,
Try with location.href

Regards,
Y. Keerthi Sagar.
kavita mehra
Greenhorn

Joined: Mar 14, 2009
Posts: 8
please explain what exactly you want me to do..? i am not familiar with location.href...
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874




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.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
kavita mehra
Greenhorn

Joined: Mar 14, 2009
Posts: 8
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

Joined: Jan 01, 2009
Posts: 874

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

Joined: Mar 14, 2009
Posts: 8
i got it.. it can be done.. but yes its messy.. thanks for putting me right..
 
GeeCON Prague 2014
 
subject: retrieving values from url rewritting in jsp