我正在创建一个登录页面,工程师可以通过以“engg”开头的用户名登录。问题出在登录页面,当我使用正确的密码输入正确的输入时,它会给出“非法状态异常”。在错误的输入中它工作正常。就像当我在我的 oracle 表中给出“engg140”时,它给出了异常.代码是:
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sun.java2d.pipe.GeneralCompositePipe;
import accessdb.Dao;
import accessdb.Getset;
public class AdminLogIn extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @return
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
try {
String username=request.getParameter("username");
String password=request.getParameter("password");
Getset g=new Getset();
Dao dao=new Dao();
if(username.equals("") || password.equals(""))
{
response.sendRedirect("login.jsp");
}
else{
String newuname=username.substring(0,4);
// System.out.println(""+username);
if(newuname.equals("engg"))
{
ResultSet rs=dao.EnggLogInUseridCheck(g);
System.out.println(""+newuname);
while(rs.next())
{
String uname=rs.getString("uname");
System.out.println(""+uname);
if(uname.equals(username))
{
g.setuname(username);
System.out.println(""+username);
System.out.println(""+uname);
ResultSet rs1=dao.EnggLogInPasswordCheck(g);
while(rs1.next())
{
String password1=rs1.getString("password");
if(password1.equals(password))
{ System.out.println(""+password1);
System.out.println(""+password);
response.sendRedirect("engghome.jsp");
break;
}
else
{
response.sendRedirect("login.jsp");
return;
}
}
}
}
response.sendRedirect("login.jsp");
}
else
{
response.sendRedirect("login.jsp");
return;
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
右输入的控制台输出如下:
03:31:26,265 INFO [STDOUT] engg
03:31:26,265 INFO [STDOUT] engg172
03:31:26,265 INFO [STDOUT] engg140
03:31:26,265 INFO [STDOUT] engg140
03:31:26,265 INFO [STDOUT] engg140
03:31:26,281 INFO [STDOUT] 365125
03:31:26,281 INFO [STDOUT] 365125
03:31:26,281 INFO [STDOUT] engg141
03:31:26,281 ERROR [[AdminLogIn]] Servlet.service() for
servlet
AdminLogIn threw exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)
at AdminLogIn.doGet(AdminLogIn.java:80)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)