| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 602 人关注过本帖
标题:[求助]JSP代码出错啦
只看楼主 加入收藏
飞辉
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-8-9
收藏
 问题点数:0 回复次数:6 
[求助]JSP代码出错啦

这段登陆验证的代码说cookie值传不过,怎么原因?

package com.bean;
//checkLogin.java

//import required classes
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

//class checkLogin
public class checkLogin
{
public String username = "";

public boolean check(HttpServletRequest req,HttpServletResponse res)
throws IOException,ServletException
{
String cookieName = "username";
Cookie[] myCookies = req.getCookies();
this.username = this.getCookieValue(myCookies,cookieName,"not found");
PrintWriter out = res.getWriter();
if(!this.username.equals("not found"))
{
//out.println("早上好," + this.username + "!");
return true;
}else{
out.println("登陆失败!");
return false;
}

}

public String getUserName()
{
return this.username;
}

public static String getCookieValue(Cookie[] cookies,String cookieName,String defaultValue)

{
int count = cookies.length;
for(int i=0;i<count;i++) {
Cookie cookie = cookies[i];
if (cookieName.equals(cookie.getName()))
return(cookie.getValue());
}
return(defaultValue);
}
}




报错:

信息: JK: ajp13 listening on /0.0.0.0:8009
2007-8-9 14:28:32 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/281 config=null
2007-8-9 14:28:32 org.apache.catalina.storeconfig.StoreLoader load
信息: Find registry server-registry.xml at classpath resource
2007-8-9 14:28:33 org.apache.catalina.startup.Catalina start
信息: Server startup in 9578 ms
2007-8-9 14:28:49 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at com.bean.checkLogin.getCookieValue(checkLogin.java:40)
at com.bean.checkLogin.check(checkLogin.java:19)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:62)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)

搜索更多相关主题的帖子: JSP import public 代码 java 
2007-08-09 14:59
飞辉
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-8-9
收藏
得分:0 
怎么就没朋友帮看下呢?
2007-08-09 15:19
stephen722
Rank: 1
等 级:新手上路
威 望:1
帖 子:96
专家分:0
注 册:2005-12-9
收藏
得分:0 

你有没有将变量写入到cookie里阿


从街口开始寻找城市里的好去处!
街口网-http://www.
2007-08-09 16:15
无缘今生
Rank: 2
等 级:新手上路
威 望:3
帖 子:523
专家分:7
注 册:2007-6-25
收藏
得分:0 
对cookie的操作不太清楚。

时不再来!!!
2007-08-09 16:31
飞辉
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-8-9
收藏
得分:0 
以下是引用stephen722在2007-8-9 16:15:31的发言:

你有没有将变量写入到cookie里阿

应该怎么写啊??

2007-08-09 16:53
chaiwp
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-7-2
收藏
得分:0 
没看明白,高人指点一下

2007-08-09 17:15
zplove
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:783
专家分:0
注 册:2006-7-30
收藏
得分:0 
at org.apache.jsp.index_jsp._jspService(index_jsp.java:62)

去你的tomcat下看看这个index_jsp.java:的62行

tomcat 的work 下

相信自己的没错了
2007-08-11 16:56
快速回复:[求助]JSP代码出错啦
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030053 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved