• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using java in jsp

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using print statements in JSPs is not best practice, it's WORST practice!

Best practice is to use JSTL.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic