Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get a href id from jsp to servlet

 
Madhuri Abhi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Cheers,
Raj.
 
Santhosh ayiappan
Ranch Hand
Posts: 80
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1625
5
Android Java Java ME
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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}"/>>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic