首页上一页 1 下一页尾页 5 条记录 1/1页
《Java Web程序开发范例宝典(1CD)》遇到的问题
发表在JavaWeb图书答疑
2010-03-01
是否精华
是
否
版块置顶:
是
否
我在第八章《结合JSTL与EL技术开发通讯录模块》遇到这样一个问题,注册模块运行没有问题,但是在我登陆的时候就会抛出IllegalStateException 异常,具体的异常是这样的
org.apache.jasper.JasperException: org.apache.jasper.JasperException: java.lang.IllegalStateException: Exception occurred when flushing data
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:31)
com.servlet.LinkmanServlet.query(LinkmanServlet.java:287)
com.servlet.LinkmanServlet.doGet(LinkmanServlet.java:39)
com.servlet.LinkmanServlet.doPost(LinkmanServlet.java:21)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:31)
com.servlet.UserServlet.login(UserServlet.java:125)
com.servlet.UserServlet.doPost(UserServlet.java:27)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:31)
下面还有一大段的异常,主要有
org.apache.jasper.JasperException: java.lang.IllegalStateException: Exception occurred when flushing data
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:429)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:31)
com.servlet.GroupServlet.query_add(GroupServlet.java:77)
com.servlet.GroupServlet.doGet(GroupServlet.java:28)
com.servlet.GroupServlet.doPost(GroupServlet.java:34)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
org.apache.jsp.linkmanAdd_jsp._jspService(linkmanAdd_jsp.java:112)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:31)
请问这是什么原因呢???
代码是这样的:
login.jsp中的表单
<form name="form1" method="post" action="UserServlet?action=login" onSubmit="return check(this)">
UserServlet中的login方法
public void login(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
String name = request.getParameter("user");
String pwd = request.getParameter("pwd");
String message = "";
ConnDB conn = new ConnDB();
String sql = "SELECT * FROM tb_user WHERE name='"+name+"'";
ResultSet rs = conn.executeQuery(sql);
try
{
int id = 0;
if(rs.next())
{
id = rs.getInt("id");
if(pwd.equals(rs.getString("pwd")))
{
HttpSession session = request.getSession();
session.setAttribute("user", name);
session.setAttribute("id", id);
request.getRequestDispatcher("LinkmanServlet?action=query").forward(request,response);
return;
}
else
{
message = "您输入的用户名或密码错误!";
}
}
else
{
message = "您输入的用户名或密码错误!";
}
}
catch(SQLException e)
{
e.printStackTrace();
message = "登陆失败!";
}
finally
{
conn.close();
}
request.setAttribute("message", message);
request.getRequestDispatcher("deal.jsp").forward(request, response);
}
LinkmanServlet中的query方法
public void query(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
ConnDB conn = new ConnDB();
int id = Integer.parseInt(request.getSession().getAttribute("id").toString());
String sql = "SELECT COUNT(*) FROM tb_linkman WHERE byUser="+id+"";
ResultSet rs = conn.executeQuery(sql);
int count = 0;
try
{
if(rs.next())
{
count = rs.getInt(1);
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
conn.close();
}
request.setAttribute("linkmanCount",count);
request.getRequestDispatcher("main.jsp").forward(request,response);
}
好像登陆的时候并没有调用GroupServlet的query_add方法,这个为什么要报错呢???
org.apache.jasper.JasperException: org.apache.jasper.JasperException: java.lang.IllegalStateException: Exception occurred when flushing data
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:31)
com.servlet.LinkmanServlet.query(LinkmanServlet.java:287)
com.servlet.LinkmanServlet.doGet(LinkmanServlet.java:39)
com.servlet.LinkmanServlet.doPost(LinkmanServlet.java:21)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:31)
com.servlet.UserServlet.login(UserServlet.java:125)
com.servlet.UserServlet.doPost(UserServlet.java:27)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:31)
下面还有一大段的异常,主要有
org.apache.jasper.JasperException: java.lang.IllegalStateException: Exception occurred when flushing data
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:429)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:31)
com.servlet.GroupServlet.query_add(GroupServlet.java:77)
com.servlet.GroupServlet.doGet(GroupServlet.java:28)
com.servlet.GroupServlet.doPost(GroupServlet.java:34)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
org.apache.jsp.linkmanAdd_jsp._jspService(linkmanAdd_jsp.java:112)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:31)
请问这是什么原因呢???
代码是这样的:
login.jsp中的表单
<form name="form1" method="post" action="UserServlet?action=login" onSubmit="return check(this)">
UserServlet中的login方法
public void login(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
String name = request.getParameter("user");
String pwd = request.getParameter("pwd");
String message = "";
ConnDB conn = new ConnDB();
String sql = "SELECT * FROM tb_user WHERE name='"+name+"'";
ResultSet rs = conn.executeQuery(sql);
try
{
int id = 0;
if(rs.next())
{
id = rs.getInt("id");
if(pwd.equals(rs.getString("pwd")))
{
HttpSession session = request.getSession();
session.setAttribute("user", name);
session.setAttribute("id", id);
request.getRequestDispatcher("LinkmanServlet?action=query").forward(request,response);
return;
}
else
{
message = "您输入的用户名或密码错误!";
}
}
else
{
message = "您输入的用户名或密码错误!";
}
}
catch(SQLException e)
{
e.printStackTrace();
message = "登陆失败!";
}
finally
{
conn.close();
}
request.setAttribute("message", message);
request.getRequestDispatcher("deal.jsp").forward(request, response);
}
LinkmanServlet中的query方法
public void query(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
ConnDB conn = new ConnDB();
int id = Integer.parseInt(request.getSession().getAttribute("id").toString());
String sql = "SELECT COUNT(*) FROM tb_linkman WHERE byUser="+id+"";
ResultSet rs = conn.executeQuery(sql);
int count = 0;
try
{
if(rs.next())
{
count = rs.getInt(1);
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
conn.close();
}
request.setAttribute("linkmanCount",count);
request.getRequestDispatcher("main.jsp").forward(request,response);
}
好像登陆的时候并没有调用GroupServlet的query_add方法,这个为什么要报错呢???