由jsp页面跳转到servlet的时候,浏览器中出现了这行文字,求教原因(PS:servlet中已经重写了doGet和doPost方法)
servlet代码如下:
1 package jsp04;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.text.SimpleDateFormat;
6 import java.util.Date;
7 import java.util.Map;
8
9 import javax.servlet.ServletException;
10 import javax.servlet.http.HttpServlet;
11 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletResponse;
13 import javax.servlet.jsp.jstl.sql.Result;
14
15 public class Zj04_sj1_reply extends HttpServlet {
16
17 public void doGet(HttpServletRequest request, HttpServletResponse response)
18 throws ServletException, IOException {
19 this.doPost(request, response);
20 }
21
22 public void doPost(HttpServletRequest request, HttpServletResponse response)
23 throws ServletException, IOException {
24
25 response.setContentType("text/html;charset=gbk");
26 PrintWriter out = response.getWriter();
27
28 //获取用户、时间
29 String userName=request.getSession().getAttribute("userName").toString();
30 Date now=new Date();
31 SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
32 String commentTime=sdf.format(now);
33
34 //获取页面数据
35 String theme=request.getParameter("theme");
36 String reply=request.getParameter("reply");
37
38 //更新comment表
39 String sql="insert into comment values(?,?,?)";
40 Object params[]={userName,commentTime,reply};
41 DBHelp.runSelectSql2(sql, params);
42
43 //更新news表
44 //先查询作者和创建日期
45 String sql2="select * from news where title=?";
46 Object params2[]={theme};
47 Result result=DBHelp.runSelectSql(sql2, params2);
48 Map row=result.getRows()[0];
49 int answerNumber=Integer.parseInt(row.get("answerNumber").toString());
50 int visitNumber=Integer.parseInt(row.get("visitNumber").toString());
51 //更改
52 answerNumber=answerNumber+1;
53 visitNumber=visitNumber+1;
54 String sql3="update news set answerNumber=?" +
55 " and visitNumber=? and finalCommentator=? and finalCommentTime=? " +
56 "where title=?";
57 Object params3[]={answerNumber,visitNumber,userName,commentTime,theme};
58 DBHelp.runSelectSql2(sql3, params3);
59
60 //更新forum表
61 //从session中获取话题
62 String topic=request.getAttribute("topic").toString();
63 String sql4="update forum set answerNumber=(1+(select answerNumber from forum where topic=?)) where topic=?";
64 Object params4[]={topic,topic};
65 DBHelp.runSelectSql2(sql4, params4);
66
67 //转发到Zj04_sj1_theme.jsp
68 request.getRequestDispatcher("jsp04/Zj04_sj1_theme.jsp");
69 }
70
71 }
jsp代码如下:
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <%
3 String path = request.getContextPath();
4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5 %>
6
7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
8 <html>
9 <head>
10 <base href="<%=basePath%>">
11
12 <title>主题回复</title>
13
14 <meta http-equiv="pragma" content="no-cache">
15 <meta http-equiv="cache-control" content="no-cache">
16 <meta http-equiv="expires" content="0">
17 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
18 <meta http-equiv="description" content="This is my page">
19 <!--
20 <link rel="stylesheet" type="text/css" href="styles.css">
21 -->
22 <style>
23 #main{
24 width:768px;
25 height:500px;
26 border:1px dashed black;
27 background-color:#FFF3D9;
28 }
29 #top{
30
31 text-align:center;
32 height:30px;;
33 border:1px dashed black;
34 margin:7px;
35 }
36 #content{
37 height:400px;
38 border:1px dashed black;
39 margin:7px;
40 }
41 #c1{
42 width:25%;
43 height:400px;
44 border:1px dashed black;
45 background-color:#FFF3D9;
46 float:left;
47 text-align:center;
48 }
49 #span{
50 vertical-align:middle;
51 margin-top:150px;
52 }
53 #c2{
54 width:72%;
55 height:400px;
56 border:1px dashed black;
57 background-color:white;
58 float:right;
59 }
60 #reply{
61 width:100%;
62 height:400px;
63 }
64 #footer{
65 height:35;
66 border:1px dashed black;
67 margin:7px;
68 }
69 #btn{
70 float:right;
71 margin-right:10px;
72 margin-top:4px;
73 }
74 </style>
75 </head>
76
77 <body>
78 <form name="form5" method="post" action="Zj04_sj1_reply">
79 <div id="main">
80 <div id="top"><span name="theme" values="浙江首条高速铁路通车">浙江首条高速铁路通车</span> 主题回复</div>
81 <div id="content">
82 <div id="c1"><div id="span" >回复内容</div></div>
83 <div id="c2"><textarea name="reply" id="reply" name="reply"></textarea></div>
84 </div>
85 <div id="footer">
86 <div id="btn">
87 <input type="submit" value="提交"/>
88 <input type="reset" value="重置"/>
89 </div>
90 </div>
91 </div>
92 </form>
93 </body>
94 </html>
添加回答
举报
0/150
提交
取消