开发者

Passing parameters through URLs

I've written a servlet which queries a datab开发者_JAVA技巧ase 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.


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...


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>");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜