java.lang.IllegalStateException
org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:423)
经过分析、查看jdk文档终于找到解决的办法,在response.sendRedirect()方法后加return语句即可,如下:
response.sendRedirect(login.jsp);
return null;
原因是:在程序中两次调用了response.sendRedirect()方法.
jdk5.0文档中很清楚地介绍了出现IllegalStateException异常的可能情况:
1)同一个页面中再次调用response.sendRedirect()方法.
2)提交的URL错误,即不是个有效的URL.

package com.servlet;

import java.io.*;
import java.sql.*; import javax.servlet.http.*;
import javax.servlet.*;
import javax.swing.JOptionPane; import com.bean.DataByPage;
import com.sun.rowset.CachedRowSetImpl; public class Handlemodify extends HttpServlet { /**
*
*/
private static final long serialVersionUID = 1L;
@SuppressWarnings("restriction")
CachedRowSetImpl rowSet = null; @Override
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
super.init(config); try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (Exception e) {
System.out.println("没有加载到驱动");
}
} @Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub req.setCharacterEncoding("gb2312");
HttpSession session = req.getSession(true);
/*
* true: 如果session存在,则返回该session,否则创建一个新的session; false:
* 如果session存在,则返回该session,否则返回null.
*/
String Id = req.getParameter("identity");
String password = req.getParameter("password").trim();
String again_password = req.getParameter("again_password").trim();
// boolean b = password.length() > 0 && again_password.length() > 0;
Connection con = null;
String cdn = "";
DataByPage dataBean = null;
try {
dataBean = (DataByPage) session.getAttribute("dataBean");
if (dataBean == null) {
dataBean = new DataByPage();// 创建对象
session.setAttribute("dataBean", dataBean);
}
} catch (Exception exp) {
dataBean = new DataByPage();// 创建对象
session.setAttribute("dataBean", dataBean);
}
if (password == null)
password = "";
if (!password.equals(again_password)) {
// userBean.setBackNews("两次密码不同,注册失败");
JOptionPane.showMessageDialog(null, "你输入的密码不同,请重新输入", "error",
JOptionPane.ERROR_MESSAGE);
resp.sendRedirect("/demo9/student/modify.jsp");
return;//这里得加个return 不然会报java.lang.IllegalStateException
} try {
con = DriverManager.getConnection(
"jdbc:sqlserver://127.0.0.1:1433;DatabaseName=manage",
"wyc", "123456");
Statement sql = con
.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
cdn = "update users set password='" + password + "'"
+ "where Idnumber='" + Id + "'";
ResultSet rs = sql.executeQuery(cdn);
rowSet = new CachedRowSetImpl();
rowSet.populate(rs);// 将rs记录转载到CachedRowSetImpl对象中,然后关闭数据库连接,释放资源
dataBean.setRowSet(rowSet);
con.close(); } catch (SQLException ex) {
System.out.println(ex);
}
resp.sendRedirect("/demo9/tiaozhuan.jsp");
}
}

java.lang.IllegalStateException的更多相关文章

  1. myeclipse 无法启动 java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).

    把myeclipse10 按照目录完整拷贝到了另外一台电脑, 另外的目录 原安装目录 D\:\soft\i\myeclipse10 新安装目录 E\:\soft\myeclipse10 双击启动失败, ...

  2. java.lang.IllegalStateException:Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx...}: java.lang.IllegalSta ...

  3. java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead

    java.lang.IllegalStateException: Not allowed to create transaction on sharedEntityManager - use Spri ...

  4. java.lang.IllegalStateException: getOutputStream() has already been called for this response

    ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang ...

  5. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this response

    1. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this ...

  6. eclipse启动报错java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' befo

    报错: java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invo ...

  7. java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data fr

    Android中操作Sqlite遇到的错误:java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. ...

  8. java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

    在ViewPager中,用Fragment显示页面时,报错: java.lang.IllegalStateException: The specified child already has a pa ...

  9. java.lang.IllegalStateException:Web app root system property already set to different value 错误原因及解决 Log4j

    Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口 服务器.NT的事件记录器.UNIX Syslog守护进程等: ...

  10. 关于viewpager 里嵌套 listview 同时实现翻页功能的“java.lang.IllegalStateException: The specified child..."异常处理

    这几天做项目用到了ViewPager,因为它可以实现左右划动多个页面的效果,然后 再每个页面里使用ListView,运行时总是出现”PagerAdapter java.lang.IllegalStat ...

随机推荐

  1. 卸载 Cloudera Manager 5.1.x.和 相关软件【官网翻译】

    问题导读: 1.不同的安装方式,卸载方法存在什么区别?2.不同的操作系统,卸载 Cloudera Manager Server and 数据库有什么区别? 重新安装不完整如果你来到这里,因为你的安装没 ...

  2. 现代程序设计 homework-05

    本次作业要求设计服务器和客户端,由于之前对网络编程是一窍不通,上上节课听宗学长讲述Tcp的时候心里想这个东西还真是高大上啊一点儿都听不懂,但是上个周末看了看C#网络编程的博客和书之后,发现这个东西入门 ...

  3. vector 之 find 重载

    众所周知,map有find,但vector的find只能调用algorithm中的find通用方法. 参考<How to find an item in a std::vector?> 对 ...

  4. 修复Debian(Ubuntu)Grub2 引导

    重装win7, 之前的系统debian 的引导就没有了. 而debian 的盘似乎没有ubuntu的livecd模式,于是用ultraISO将ubuntu的ios文件写入到u盘中. boot时选择启动 ...

  5. 递归函数recursion

    1(调用自身)递归函数是‘自己调用自己‘的函数,不管这样的调用是直接的还是间接的. 2(递归出口)因为函数不可以一直调用自己,无法停止工作,所以递归函数一定具备结束条件. http://www.cnb ...

  6. MySQL索引的创建,查看,删除

    在执行CREATE TABLE语句时可以创建索引,也可以单独用CREATE INDEX或ALTER TABLE来为表增加索引. 1.ALTER TABLE ALTER TABLE用来创建普通索引.UN ...

  7. Codeforces Round #362 (Div. 2) C. Lorenzo Von Matterhorn (类似LCA)

    题目链接:http://codeforces.com/problemset/problem/697/D 给你一个有规则的二叉树,大概有1e18个点. 有两种操作:1操作是将u到v上的路径加上w,2操作 ...

  8. mysql case when 条件过滤

    [1].[代码] 使用CASE WHEN进行字符串替换处理 跳至 [1] [2] [3] [4] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2 ...

  9. MongoDB 快速入门--初级

    数据库的操作一般来说都是CRUD,这其中最难的就是查询,所有所我们先来了解MongoDB中的 插入(insert) 说到插入,我们就必须得说说如何创建数据库,如何创建集合,然后才是如何创建文档. 在这 ...

  10. 一种基于Welch's t检验的二元关系挖掘

    现实中常常需要挖掘两种因素之间的关联,Welch's t检验很适合其中的nomial-numerical的关系挖掘.比如天气状况对销量的影响,或者天气情况对交通流量的影响等等.我们可以按照下雨/不下雨 ...