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. 个人思考:能否sub.prototye=sup.prototype实现继承

    var Sup=function(name){ this.name=name; }; var Sub=function(name){ this.name=name; }; Sup.prototype. ...

  2. Uva 208 - Firetruck

    [题目链接]http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&p ...

  3. Hibernate关联关系之双向1—n

    •双向 1-n 与双向 n-1 是完全相同的两种情形 •双向 1-n 需要在1的一端可以访问n的一端,反之依然. 测试实例代码: 实体类: package com.elgin.hibernate.nt ...

  4. 各个版本spring的jar包以及源码下载地址

    各个版本spring的jar包以及源码下载地址,目前最高版本到spring4.1.2,留存备用: http://maven.springframework.org/release/org/spring ...

  5. 07 java main方法

    1.问题:Java main方法为什么是  public static void main(String[] args)??? 序号 场景 编译 运行 解释 1 public修改为private pr ...

  6. [iOS UI进阶 - 3.1] 触摸事件的传递

    A.事件的产生和传递 发生触摸事件后,系统会将该事件加入到一个由UIApplication管理的事件队列中UIApplication会从事件队列中取出最前面的事件,并将事件分发下去以便处理,通常,先发 ...

  7. NGUI学习笔记(五):缓动

    在Unity3D中可以使用自带的Animation制作任意形式的动画,不过我们这篇笔记主要是学习和使用NGUI提供的Tween动画.NGUI提供的Tween库功能较为简单,主要是用来实现NGUI自身需 ...

  8. 多浏览器兼容flv视频播放HTML

    HTML: <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http: ...

  9. GMT 绘制台站分布图

    set ps=test.psset J=M4i set R=73/135.5/10/54rem gmt gmtset  FONT_ANNOT_PRIMARY 8p FONT_TITLE 8p  gmt ...

  10. iOS开发-block使用与多线程

    Block Block封装了一段代码,可以在任何时候执行 Block可以作为函数参数或者函数的返回值,而其本身又可以带输入参数或返回值. 苹果官方建议尽量多用block.在多线程.异步任务.集合遍历. ...