java.lang.IllegalStateException
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的更多相关文章
- 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 双击启动失败, ...
- 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 ...
- 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 ...
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang ...
- 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this response
1. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this ...
- eclipse启动报错java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' befo
报错: java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invo ...
- 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. ...
- 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 ...
- java.lang.IllegalStateException:Web app root system property already set to different value 错误原因及解决 Log4j
Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口 服务器.NT的事件记录器.UNIX Syslog守护进程等: ...
- 关于viewpager 里嵌套 listview 同时实现翻页功能的“java.lang.IllegalStateException: The specified child..."异常处理
这几天做项目用到了ViewPager,因为它可以实现左右划动多个页面的效果,然后 再每个页面里使用ListView,运行时总是出现”PagerAdapter java.lang.IllegalStat ...
随机推荐
- 怎么利用SQL语句查询数据库中具体某个字段的重复行
select * from [tablename] group by SeriNohaving count(SeriNo)<>1
- MEAN stack 做网站【1】
做一个小project,学习如何用MEAN技术栈来搭建网站. JavaScript新手,不足之处,请指出.(系统为win10) 搭建环境: 安装Node.JS (略过) 安装MySQL,MongoDB ...
- eucalyptus,openNebula云构建漫谈
Eucalyptus篇 万事在于理解,技术研究贵在入脑入心.生活很苦,乐趣何在,在于君心?不能修心,则诸事繁杂!闲来无事,阅读官网文档遇此 two Why selecter?因此分享给亲们!亲,那么我 ...
- VS2012编译可在WinXP兼容程序
VS2012需要安装Update 1补丁 在Project的属性 选择 配置属性 - 常规 - 平台工具集 - Visual Studio 2012 - Windows XP (v110_xp) 在P ...
- 1分钟内检查Linux服务器性能的10条命令
如果你的Linux服务器突然负载暴增,告警短信快发爆你的手机,如何在最短时间内找出Linux性能问题所在?Netflix性能工程团队的Brendan Gregg写下了这篇博文,来看他们是怎样通过十条命 ...
- Linux下文件的权限
一.Linux下查看文件属性 命令为: [root@localhost ~]# ls -al 结果: ls是『list』的意思,重点在显示文件的文件名与相关属性.而选项『-al』则表示列出所有的文件详 ...
- 无奈卸载Clover 转投TotalCommand
Clover 是个好的多Tab 资源管理器,但在Win8下总是崩溃啊,让人很崩溃. 无奈投奔TotalCommand吧,就是梯度有些高. 当然不习惯,也可以使用下 XYPlorer
- 【转】深受开发者喜爱的10大Core Data工具和开源库
http://www.cocoachina.com/ios/20150902/13304.html 在iOS和OSX应用程序中存储和查询数据,Core Data是一个很好的选择.它不仅可以减少内存使用 ...
- OpenCDN2.0安装
部署说明 为网站加速,建立私有的CDN节点群,每部署一个CDN节点只需5分钟,无节点数量上限!参考 http://ocdn.me/ 安装需求 OpenCDN的Beta版目前在CentOS5.x - C ...
- HDU 4438 Hunters (数学,概率计算)
题意:猎人A和B要进行一场比赛.现在有两个猎物老虎和狼,打死老虎可以得X分,打死狼可以得Y分.现在有两种情况: (1)如果A与B的预定目标不同,那么他们都将猎到预定的目标. (2)如果A与B的预定目标 ...