The moose likes JSP and the fly likes Whats wrong with this line of code??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Whats wrong with this line of code???" Watch "Whats wrong with this line of code???" New topic

Whats wrong with this line of code???

Annemarie McKeown
Ranch Hand

Joined: Nov 07, 2003
Posts: 47
I get the following values from the database:
String topicid = rs.getString("topicid");
String title = rs.getString("title");
And I can display these in broswer ok, simply out.print("topicd"); etc...
However when I want to print out the title, and make it a link to open up a new jsp page displayTopic.jsp?topicid='"+topicid+"' ( from resultSet rs),
it doesn't seem to display the title as a link properly in the browser.
Can anyone spot any obvious errors in the following line of code:
out.print("<td width='60%'><a href='displayTopic.jsp?topicid='"+topicid+"' '>" + title + "</a></td>");
Some help please....???
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30146


Note that these two pieces of code are different. The first displays the six letters "topicd". The second prints the value of the variable topicd. You want the second one to make sure the variable contains what you want it to.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Annemarie McKeown
Ranch Hand

Joined: Nov 07, 2003
Posts: 47
Sorry my mistake I should have actually written out.print(topicid);
Thats not where my problem is though, something within the long line code out.print("<td>".........
is not displaying in the browser as it should.
I want it to display
title as a link, the user can click on title which will open a new page, passing topicid (?topicd=topicid).
Do you know whats wrong with that line of code.?
Adrian Pang
Ranch Hand

Joined: Feb 20, 2004
Posts: 40
If you want topicid=xxx, don't u want
out.println("<td width='60%'><a href='displayTopic.jsp?topicid="+topicid+"'>"...)
instead of:
out.print("<td width='60%'><a href='displayTopic.jsp?topicid='"+topicid+"' >");'>" + title + "</a></td>
(you have an extra ' in the code originally)
which gives you
topicid='xxx' ?
perhaps you should just right click on the link (if you are using IE) and copy shortcut so you can tell what the link points to?
[ March 07, 2004: Message edited by: Adrian Pang ]
[ March 07, 2004: Message edited by: Adrian Pang ]

SCJP 1.4, SCWCD 1.4, SCBCD 1.3
I agree. Here's the link: http://aspose.com/file-tools
subject: Whats wrong with this line of code???
Similar Threads
page refresh problem
Display each results from database in their own row
help with jsp
jsp:forward and jsp:include
alternate table row bgcolor using if/else