Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old January 28th, 2002, 11:48 AM
dodgie dodgie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Milton Keynes, England
Posts: 70 dodgie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 43 m 19 sec
Reputation Power: 8
Send a message via ICQ to dodgie
Passing a variable on the URL to JSP?

Hi,

I have an HTML file which contains links to some jsp scripts. I would like ot be able to pass a variable using the URL from the HTMl to the jsp script. Can anyone tell me how to do this?

If you don't know what I mean, this is what I mean in PHP:

PHP Code:
<A HREF="index.php?id=223"


Can anyone tell me how to do this? And how I retrieve the variables inside my jsp file?

Thanks

Richard
__________________
Think of the most annoyingly simple question and I've probably asked it on here!

Reply With Quote
  #2  
Old January 28th, 2002, 03:51 PM
RandReed RandReed is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Location: Belmar, NJ
Posts: 1 RandReed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Similar/ Related Question

I have a similar question. If there is a series of .jsp forms and you want to set up a link to a certain point by 'forcing' certain answers, is this even possible?

To see a site with an good example, go to the following link:

URL

This will redirect you to the next page:

URL

From here, I want to force the next page in the sequence (as if the user entered the number "1824" and clicked "Search") and the next and so on.

Is there some way to figure these out?

Thanks,
Rand

Reply With Quote
  #3  
Old January 28th, 2002, 08:45 PM
codeguru codeguru is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 1 codeguru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
/*
Note: The following answers the first post. I will tackle the second post below*/

It's the same as passing it to php as described by your example.

<!-- copy of your example -->
<a href="index.jsp?id=223">link</a>
<!-- end of example copy -->

To get access to the values in the query string do this:

<!--assuming an existing jsp page -->
<%
String id = request.getParameter( "id" );
if( null != id && !id.equals( "" ) )
{
//do something with it
}
%>

/*End of answer of answer to first post*/

/*Beginning of answer to second post*/
Its possible but you need either a servlet or JSP (MVC Patter::Controller) to figure out what and where to forward. Here is a simple example using a JSP fragment

<%
String locationID = request.getParameter( "loc" );
if( null != locationID && !locationID.equals( "" ) )
{
if( locationID.equals( "homePage" ) )
{
response.sendRedirect( "firstPage?loc=firstPage&nextPage=secondPage" );
}
else if( locationID.equals( "firstPage" ) )
{
response.sendRedirect( "secondPage?loc=secondPage&nextPage=etc" );
}
else if ......
}
%>

It's an incomplete example but what you should get from it is:
- You need a controller object (JSP or Servlet) to route the request.

- Setup a format for figuring out what to route and where to route it. In my example I had a parameter called 'loc' that had the value of the page that the user is comming from and another called 'nextPage' that tells controller object where to route the request to. A more elegant solution may be to have a Map that contains all the possible paths that the user can be routed to as the values and the name of the page that triggers the particular path as the key. So the code may look like:
String path = (String)map.get( request.getParameter( "loc" ) );
response.sendRedirect( null == path ? "errorPage.jsp" : path );

I hope that helped.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Passing a variable on the URL to JSP?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway