org.apache.jasper.JasperException: An exception occurred processing JSP page /doLogin.jsp at line 34
31: if(isUseCookies!=null&&isUseCookies.length>0){
32: //鎶婄敤鎴峰悕鍜屽瘑鐮佷繚瀛樺埌Cookies涓�
33: //1鑾峰緱鐢ㄦ埛鍚嶅拰瀵嗙爜
34: String username = URLEncoder.encode(request.getParameter("username"),"utf-8");
35: String password = URLEncoder.encode(request.getParameter("password"),"utf-8");
36: //2鍒涘缓cookies瀵硅薄
37: Cookie usernamecookies=new Cookie("username",username);
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:575)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
root cause
java.lang.NullPointerException
java.net.URLEncoder.encode(URLEncoder.java:188)
org.apache.jsp.doLogin_jsp._jspService(doLogin_jsp.java:122)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.68 logs.
看了我的代码,和老师说的一样的,哪位大神帮我看看我是哪里错了
把dologin的代码都贴上来看看呢。只看这个问题不太好看出来。
<%@ page language="java" import="java.util.*,java.net.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'doLogin.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h1>登陆成功</h1> <br>
<hr><br><br><br>
<%
request.setCharacterEncoding("utf-8");
String isUseCookies[] =request.getParameterValues("isUseCookie");
if(isUseCookies!=null&&isUseCookies.length>0){
//把用户名和密码保存到Cookies中
//1获得用户名和密码
String username = URLEncoder.encode(request.getParameter("username"),"utf-8");
String password = URLEncoder.encode(request.getParameter("password"),"utf-8");
//2创建cookies对象
Cookie usernamecookies=new Cookie("username",username);
Cookie passwordcookies=new Cookie("passwore",password);
//3设置保存时间
usernamecookies.setMaxAge(846000);
passwordcookies.setMaxAge(864000); //最大保存时间是10天.
//4保存cookie对象
response.addCookie(usernamecookies);
response.addCookie(passwordcookies);
}
else{
//如没有选择保存,则删除保存
//1先判断有无保存
Cookie cookies[]=request.getCookies();
if(cookies!=null&&cookies.length>0){
for(Cookie c:cookies){
if(c.getName().equals("username")||c.getName().equals("pw")){
c.setMaxAge(0);//设置保存时间为O
response.addCookie(c);
}
}
}
}
%>
<a href="Users.jsp" target="_blank">查看用户信息</a>
</body>
</html>