jsp条件判断网页转向问题
这是 loginok.jsp 网页
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><%=request.getServerName() %></title>
</head>
<body>
<% request.setCharacterEncoding("GBK");
String username=request.getParameter("name");
String password=request.getParameter("pass");
if(username.equals("小鱼")&&password.equals("123456"))
{%><jsp:forward page="clock.jsp"/>
<%}
/*out.println("欢迎"+username+"成功登陆聊天室系统!");*/
else response.sendRedirect("login.html");
%>
</body>
</html>
这是 clock.jsp 网页
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title> <%=request.getServerName() %></title>
</head>
<body>
<%out.println("当前时间是:"+new Date());
response.setHeader("Refresh","1");
%>
</body>
</html>
为什么会出现
org.apache.jasper.JasperException: An exception occurred processing JSP page /loginok.jsp at line 12
9: <% request.setCharacterEncoding("GBK");
10: String username=request.getParameter("name");
11: String password=request.getParameter("pass");
12: if(username.equals("小鱼")&&password.equals("123456"))
13: {%><jsp:forward page="clock.jsp"/>
14: <%}
15: /*out.println("欢迎"+username+"成功登陆聊天室系统!");*/
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handle
JspException(JspServletWrapper.java:553)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:457)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
------解决方案--------------------jsp页面不能编译,你打印下用户名是不是传入到这个页面了,一定要保证参数传过来了
------解决方案--------------------
你没有对username和password判断是否空
HTML code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><%=request.getServerName() %></title>
</head>
<body>
<% request.setCharacterEncoding("GBK");
String username=request.getParameter("name");
String password=request.getParameter("pass");
if( null!=username&&null!=password&&username.equals("小鱼")&&password.equals("123456"))
{%><jsp:forward page="clock.jsp"/>
<%}
/*out.println("欢迎"+username+"成功登陆聊天室系统!");*/
else response.sendRedirect("login.html");
%>
</body>
</html>
我的异常网推荐解决方案:An exception occ