JSP的java code + HTML表 [英] JSP java code + html table

查看:213
本文介绍了JSP的java code + HTML表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也遇到过,我真的不明白的一个问题。我用java code访问一个数据库,然后使用JSP的一部分,显示HTML格式的结果。
在code是这样的:

I have encountered a problem that I don't really understand. I'm using java code to access a database and then using the jsp part, display in html format the result. The code looks like this:

out.println("<html><body>");

out.println("<form method=\"GET\" action=\"http://localhost:1234/WebLabJSP/delete\">");

out.println("<table>");

out.println("<tr><th>Name</th><th>Quantity</th><th>Category</th></tr>");

ResultSet rs = s.executeQuery("select * from Products");


while(rs.next()){


out.println("<tr><td>" + rs.getString(2) + "</td><td>" + rs.getString(3) + "</td><td>" + rs.getString(4) + "</td><td><input type=\"submit\" value=\"Delete\" name=\"delete" + rs.getString(1) + "\"/></td><td><input type=\"submit\" value=\"Update\" name=\"update" + rs.getString(1) + "\"/></td></tr>");

   } 

out.println("</table></form>");

out.println("</body></html>");

问题是,如果我在表单只删除按钮,它完美的作品,但是当我添加第二个按钮时,页面根本没有显示任何内容。
如果有人知道这是怎么回事,请大家帮忙。

The problem is, that if I have only the delete button in the form, it works perfectly, but when I added the second button, the page didn't display anything at all. If anyone knows what's going on, please help.

推荐答案

这一切首先是不是你应该如何使用JSP。
对servlet的使用java code JSP使用JSTL。

First of all this is not how you should use jsp. On jsp use jstl on servlet use java code.

和关于您的问题,请尝试检查生成的HTML。它应该有

and about your issue try checking generated HTML. It should have

<form ...>
.
.
.
.<input type="submit" name="something" value="delete"/>
.<input type="submit" name="something" value="update"/>
</form>

或者检查服务器的日志,

Or check for server's log,

另请参见

  • How to avoid java code in jsp
  • How JSP should be written

这篇关于JSP的java code + HTML表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆