java.lang.IllegalStateException

來源:互聯網
上載者:User

標籤:boolean   redirect   div   odi   return語句   驅動   public   long   sof   

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.