aspose file tools*
The moose likes JSP and the fly likes Passing a Querystring from one page to the next Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing a Querystring from one page to the next" Watch "Passing a Querystring from one page to the next" New topic
Author

Passing a Querystring from one page to the next

Matt Hoffman
Ranch Hand

Joined: Jun 03, 2004
Posts: 83
I need to pass a value with a querystring to another page and run a query based on it.

Example:
Page 1
I would click on the following link.
<a href="deleteCD.jsp?cd_id=<%= search.getCDID() %>">Delete</a>

Page 2
I have this for my SQL in my DeleteCDBean.java file:
String cdid = "";
ResultSet results = statement.executeQuery(
"SELECT * FROM CD, ARTIST, GENRE, ADVISORY, LOCATION WHERE CD.ARTIST_ID = ARTIST.ARTIST_ID AND CD.GENRE_ID = GENRE.GENRE_ID AND CD.ADVISORY_ID = ADVISORY.ADVISORY_ID AND CD.LOCATION_ID = LOCATION.LOCATION_ID AND CD_ID = " + cdid + " ");

I also have this to get the value from the URL:
<%
String cdid = request.getParameter("cd_id");
%>

For some reason I can't get the cd_id that is passed from the 1st page to insert itself into the SQL.

Any suggestions?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Firstly, just basic debugging techniques. Did you check to see what the state of the parameter was after you passed it? I'm betting it was a mess because you didn't URL encode it.

Secondly, why are you passing it at all? Why not pass a simple key that you can match up to the complex query?

Thirdly: the obligatory admonition against structuring your app to do SQL in the JSPs.
[ June 05, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Matt Hoffman
Ranch Hand

Joined: Jun 03, 2004
Posts: 83
Ok thanks.. Since I am new a this, I am not sure what you mean about passing a key. Any examples are resources that I can look at?
Matt Hoffman
Ranch Hand

Joined: Jun 03, 2004
Posts: 83
I did do some debugging and I am able to pass the ID using the dynamic link to the following page. I stored the ID in a hidden field on the following page and it is displaying the correct ID.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing a Querystring from one page to the next