|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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:
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! |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
/*
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Passing a variable on the URL to JSP? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|