views:

38

answers:

2

I've written a servlet which queries a database for a list of messages, the output is directed to servlet generated html. The user has the option of selecting to view a selected message by clicking a button

ResultSet rs = null;
try
{
    startPage(response);
        rs = statement.executeQuery(sql);
        while(rs.next())
        {
            out.println("<tr>");
            out.println("<td align=center>"+rs.getString("Heading")+"</td>");
            out.println("");
            out.println("<td align=center>"+rs.getString("Username")+"</td>");
            out.println("");
            out.println("<td align=center>"+rs.getString("DatePosted")+"</td>");
            out.println("");
            out.println("<td align=center><form action=dbShowMessage?action='"+rs.getString("Heading")+"'method=post><input value=VIEW type=submit></form></td>");
            out.println("</tr>");
        }

    endPage(response);
}

The code compiles without any error, but when I invoke it using the web server the HTML page displays without the table containing the results or the buttons, but as soon as I remove the it displays everything; what am I doing wrong here.

Alternatively I tried it with a URL as follows:

out.println("<tr>");
out.println("<td align=center><a href=dbShowMessage?title="+rs.getString("Heading")+">"+rs.getString("Heading")+"</a></td>");
out.println("");
out.println("<td align=center>"+rs.getString("Username")+"</td>");
out.println("");
out.println("<td align=center>"+rs.getString("DatePosted")+"</td>");
out.println("");
out.println("</tr>");

Again it's the same out come; the links and the table displayed after invocation but as soon as I create the reference same story.

+1  A: 

Not sure if it solves your problem, but you may want to put a space before the method attribute, that is, change

...Heading")+"'method=post...

to

...Heading")+"' method=post...

Besides this, what characters does your heading actually include? No citation-marks I assume...

aioobe
A: 

You have invalid html...

Use this line:

out.println("<td align=center><form action=\"dbShowMessage?action='"+rs.getString("Heading")+"'\" method=\"post\"><input value=\"VIEW\" type=\"submit\"></form></td>");
me_delete
@me_delete - Thanks for the reply, but it's not working for some reason, it prints the first record and stops where it should display the button
Kushan