我的servlet问题
我的servlet访问数据库后用request.getRequestDispatcher(path).forword(request.response);转发到指定JSP页面。
今天调试访问该servlet的映射ViewMessageServlet,却不能跳转,页面为空白页,没有任何错误信息提示,我不知道是什么原因,因为昨天测试都是正常的,没有改动过代码,今天却不行了,经过在该Servlet的doGet()方法里添加代码:
PrintWriter out=response.getWriter();将out.print( "test <br/> ");代码分别置于servlet的doGet()方法里几个位置,再次访问,发现页面有显示出几个test,直到最后跳转页面代码之前也放了一句out.print( "test <br/> ");,此test确定是被输出到了浏览器的,但就是没有发生跳转!是什么原因呢?
ViewMessageServlet代码如下:
package com.iven.mes;
import java.sql.Connection;
import java.sql.Date;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import
java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;
import
java.io.IOException;
import
javax.servlet.ServletException;
import java.io.PrintWriter;
public class ViewMessageServlet extends HttpServlet
{
Connection con;
public ViewMessageServlet()
{
String s= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
String s1= "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=sczy ";
String s2= "iven ";
String s3= "ivenhuang ";
try
{
Class.forName(s);
con=DriverManager.getConnection(s1,s2,s3);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)throws
IOException,
ServletException {
response.setContentType( "text/html;charset=gb2312 "); //必须在方法里的第一行代码,使后面转向的页面也能同步编码格式,如果不加这句,
//转向的jsp页面中的汉字将变成乱码!
request.setCharacterEncoding( "gb2312 "); //编码存入数据库中的数据,使汉字不会存在乱码!
PrintWriter out=response.getWriter();
ArrayList arraylist=new ArrayList();
try
{
Statement stm=con.createStatement();
ResultSet resultset=stm.executeQuery( "select count(*) from sczy_messageboard ");
int i=0;
if(resultset.next())
{
i=resultset.getInt(1);//取得第一条纪录中的第一列(数据库中字段为num的自增字段)的值;
resultset.close();
}
if(i> 0)
{
ResultSet resultset1;
MessageBean messagebean;
for(resultset1=stm.executeQuery( "select * from sczy_messageboard order by thedate desc ");resultset1.next();arraylist.add(messagebean))
{
int num=resultset1.getInt(1);
String users=resultset1.getString(2);
String phone=resultset1.getString(3);
String fax=resultset1.getString(4);
String email=resultset1.getString(5);
String company=resultset1.getString(6);
String heading=resultset1.getString(7);
String content=resultset1.getString(8);
java.util.Date &nbs