The most intelligent Java IDE
[Logo] JavaRanch » Big Moose Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JSP
 
RSS feed
 
New topic
Author

retrieving values from url rewritting in jsp

kavita mehra
Greenhorn

Joined: Mar 14, 2009
Messages: 8

how to get the values passed by url rewritting from the same jsp?
Jeanne Boyarsky
internet detective
Sheriff

Joined: May 26, 2003
Messages: 17206

What values? The parameters? The session id?

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]

"The set strikes me as something like the set of potatoes, radishes, farming, and lunch. " - a colleague's way of comparing both overlapping and disparate groups. made me laugh and thought of the ranch
kavita mehra
Greenhorn

Joined: Mar 14, 2009
Messages: 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
Messages: 355

Are you doing something like this ::

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




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

Joined: Mar 14, 2009
Messages: 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
Ranch Hand

Joined: Mar 24, 2008
Messages: 1988

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.

This message was edited 1 time. Last update was at by Vijitha Kumara


SCJP 5, SCWCD 5
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Messages: 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
Messages: 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
Ranch Hand

Joined: Mar 24, 2008
Messages: 1988

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.. ?

This message was edited 1 time. Last update was at by Vijitha Kumara


SCJP 5, SCWCD 5
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Messages: 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
Messages: 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
Messages: 26

Hi Kavitha,
Try with location.href

Regards,
Y. Keerthi Sagar.
kavita mehra
Greenhorn

Joined: Mar 14, 2009
Messages: 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
Messages: 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.



This message was edited 1 time. Last update was at by Balu Sadhasivam

Bear Bibeault
Author and opinionated walrus
Sheriff

Joined: Jan 10, 2002
Messages: 36608

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.

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
kavita mehra
Greenhorn

Joined: Mar 14, 2009
Messages: 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
Messages: 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 .

This message was edited 1 time. Last update was at by Balu Sadhasivam

kavita mehra
Greenhorn

Joined: Mar 14, 2009
Messages: 8

i got it.. it can be done.. but yes its messy.. thanks for putting me right..
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JSP
 
RSS feed
 
New topic
JProfiler
Get rid of your performance problems and memory leaks!