• Post Reply Bookmark Topic Watch Topic
  • New Topic

using java in jsp

 
Rinky Deshmukh
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have retrived some data from database and displayed in a form but i'm not able to get how to give different hyperlinks to the different data .
jsp: retrived subject names from the form and displayed in another form
while(rs.next())
{
sub_name=rs.getString();
}

%>
<%=sub_name%>

i want to link different sub names to different pages .


can any one help me out


thank U
 
Tom George
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Q seems a bit vague.

1. If there are not a large number of such URLs you can simply construct the link in the loop -
while(rs.next())
{
out.println("<a href="+ link +"+ content+">");
}

2. otherwise, store the urls in some table, retrieve it in the query suitably and construct the link..

Hope this gives you some lead.
 
Charles Chen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
give different hyperlinks to the different data .


May need if statement too.
 
Rinky Deshmukh
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the answers
it worked out as:
<a href="link_page?variable=<%=sub_name%>><%=sub_name%></a>
link_page:
string name=request.getParameter(variable above declared);
 
Tom George
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a good practice you should be using out.println() repetitively instead of fighting with <% tags :-) As behind the scenes, the compiler has to convert it to strings again .

<a href="link_page?variable=<%=sub_name%>><%=sub_name%></a>
becomes
out.println("<a href=");
out.println(variable);
.
.
.

This may gain you some performance, especially if it runs inside a long loop.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the compiler has to convert it to strings again

Hmm. Well, its only going to do this once so I wouldn't worry too much about it. In a production enviroment you'd precompile the JSPs anyway.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a good practice you should be using out.println()


As Paul points out, this is bad advice. Do not worry about optimizing prematurely -- rather concentrate on keeping your code clear. Avoid out.println() and use template text to its best advantage.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using print statements in JSPs is not best practice, it's WORST practice!

Best practice is to use JSTL.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!