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. sizeof 字符数组

    比较 #include <stdio.h> #include <string.h> int main(int argc, const char *argv[]) { char ...

  2. UVALive 7324 ASCII Addition (模拟)

    ASCII Addition 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/A Description Nowadays, th ...

  3. poj 1517 u Calculate e

    u Calculate e Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19465   Accepted: 11362   ...

  4. POJ1189钉子和小球(DP)

    对钉子DP,如果钉子存在DP[i+1][j]+=DP[i][j]; DP[i+1][j+1]+=DP[i][j]; 如果不存在DP[i+2][j+1]+=4*DP[i][j]; 见代码:(有一个比较坑 ...

  5. PostgreSQL的 initdb 源代码分析之二十三

    继续分析: vacuum_db(); 展开: cmd是:/home/pgsql/project/bin/postgres" --single -F -O -c search_path=pg_ ...

  6. 使用Filter防止浏览器缓存页面或请求结果

    仅仅须要两步: 1.定义一个Filter: /** * 防止浏览器缓存页面或请求结果 * @author XuJijun * */ public class NoCacheFilter impleme ...

  7. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  8. C#.net 之货币转换

    利用string.format 和cultureInfo 来进行转换 /// <summary> /// 输入Float格式数字,将其转换为货币表达方式 /// </summary& ...

  9. C++技术问题总结-第12篇 设计模式原则

    设计模式六大原则,參见http://www.uml.org.cn/sjms/201211023.asp. 1. 单一职责原则 定义:不要存在多于一个导致类变更的原因.通俗的说,即一个类仅仅负责一项职责 ...

  10. android UI进阶之实现listview中checkbox的多选与记录

    今天继续和大家分享涉及到listview的内容.在很多时候,我们会用到listview和checkbox配合来提供给用户一些选择操作.比如在一个 清单页面,我们需要记录用户勾选了哪些条目.这个的实现并 ...