aspose file tools*
The moose likes JSP and the fly likes Get a href id from jsp to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Get a href id from jsp to servlet" Watch "Get a href id from jsp to servlet" New topic
Author

Get a href id from jsp to servlet

Madhuri Abhi
Greenhorn

Joined: Jun 29, 2011
Posts: 11
Hi all,

can i get ahref id value from jsp to a servlet?? Is so, is the following code correct???






Thanks,
Madhuri

Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


I would assume that you get the value 'name'. What happens when you try it?

Cheers,
Raj.
Santhosh ayiappan
Ranch Hand

Joined: Jan 30, 2007
Posts: 80

Yes, you can get the value as below. But it is not good practice to hardcode the values in the URL.

~Santhosh
Madhuri Abhi
Greenhorn

Joined: Jun 29, 2011
Posts: 11
Raj,

There is no error but nothing is shown in the page.

Santosh,

What i am actually doing is displaying the values in jsp page(in a table) from database. and when one of those fields is clicked, corresponding value should be shown.

To make it more clear, say suppose i have id(varchar), name(varchar) and content(blob) fileds in database. I get id and name in jsp page and display it in a table. when i click on the name, it redirects to a servlet thereby corresponding content should be displayed.

For this, i need to know which name he has clicked.






What i actually do in the below code is that i display the name field from database. and so when i click on any of the names in the jsp page, corresponding content should be shown.
<td width="168"><a href="/imageAndDoc/downloadFileServlet"?id=<%out.println(rs.getString("name"));%>><%out.println(rs.getString("name"));%></a></td>



mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 244

Santhosh ayiappan wrote: But it is not good practice to hardcode the values in the URL.

~Santhosh


Then how to pass that id, please tell me if any methode is there thanks
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


You could use the parameter as a FORM field (hidden-field) if necessary. I do not see any issues with passing a parameter as part of the query string parameter. Parameters in GET requests go that way anyways.

Cheers,
Raj.
Prity Choudhary
Greenhorn

Joined: Apr 17, 2007
Posts: 1
Hi Madhuri,

I am also working on exactly same requirement and stuck. Could you please let me know how did you resolved your issue.

Please message me the sample code.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1479
    
    6

Don't use java code inside jsp, its a very old practice. Look for JSTL,EL etc. You can pass any dynamic value in query string.
<c:set var="idval" value="10"/>
<a href=myservlet?id=<c:out value="${idval}"/>>


Swastik
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get a href id from jsp to servlet