我希望使用HttpServletResponse res.getWriter()打印此代码:
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 20%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
</style>
</head>
<body>
<form action="servlet1" method="get">
<br><br> <table>
<tr>
<td><input type="radio" name="input" value="1"> </td>
<td><input type="radio" name="input" value="2"> </td>
<td><input type="radio" name="input" value="3"> </td>
</tr>
<tr>
<td><input type="radio" name="input" value="1"> </td>
<td><input type="radio" name="input" value="1"> </td>
<td><input type="radio" name="input" value="1"> </td>
</tr>
<tr>
<td><input type="radio" name="input" value="7"> </td>
<td><input type="radio" name="input" value="8"> </td>
<td><input type="radio" name="input" value="9"> </td>
</tr>
</table>
<br><input type="submit" value="Turn Completed" />
</form>
</body>
</html>
如何在res.getWriter.println()语句中添加所有这些代码?请让我知道最简单的方法。
更具体地说:有没有什么办法可以像编写整个代码块一样编写这么多的代码……您将如何划分行?括号?括号等...?请让我知道。
谢谢!
答案 0 :(得分:0)
在servlet上打印html代码的一种方法如下
公共类HelloWorld扩展了HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html><body>");
out.println("Hello World!");
out.println("</body></html>");
out.close();
}
}