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. <Chapter 2>2-2-2.开发Java应用(Developing a Java App)

    App Engine的Java网络应用使用了Java Servlet标准接口来和应用服务器交互.一个应用由一个或多个servlet类组成,每个都扩展了(extend)servlet基类.使用一个叫做部 ...

  2. POJ 1511 Invitation Cards (最短路spfa)

    Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...

  3. HDU1973 http://acm.hdu.edu.cn/showproblem.php?pid=1973

    #include<stdio.h> #include<stdlib.h> #include<string.h> #include<queue> #inc ...

  4. UVaLive 7370 Classy (排序,比较)

    题意:给定 n 个人,和他们的数进行比较,从后面开始比,如果不够长,加middle接着比,直到没有,如果还相同比名字. 析:很水的题,就不用说了. 代码如下: #pragma comment(link ...

  5. CodeForces 706C Hard problem (水DP)

    题意:对于给定的n个字符串,可以花费a[i]  将其倒序,问是否可以将其排成从大到小的字典序,且花费最小是多少. 析:很明显的水DP,如果不是水DP,我也不会做.... 这个就要二维,d[2][max ...

  6. 山东理工大学ACM平台题答案关于C语言 1137 C/C++经典程序训练7---求某个范围内的所有素数

    C/C++经典程序训练7---求某个范围内的所有素数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 求小于n的所有素数,按照每行 ...

  7. Windows 7 bug: nonexistent Java Runtime Enviroment

    When I tried installing atunes and TED, I got the message “The registry refers to a nonexistent Java ...

  8. 创建虚拟交换机(New-VMSwitch)

    #获取网卡列表Get-NetAdapter

  9. Note of IOS 7 - Views

    1. Views presentation: A view (an object whose class is UIView or a subclass of UIView) knows how to ...

  10. Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm

    C. The Big Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/probl ...