jsp页面错误 高手帮看下

hanshuihu 2010-08-12 11:04:06
jsp页面如下
<%@ page language="java" import="java.util.*,javax.naming.*,javax.sql.*,java.sql.*,com.gt.login.*,com.gt.common.util.*,com.gt.formbean.jjd.xtgl.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
HttpSession mySession = request.getSession(true);
//错误消息
String errorMessage = "";
//获取cookie 存在则将cookie值写入登录用户名
String usernameCookie = "";
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
System.out.println("cookie:"+cookie.getName());
if ("usercookie".equals(cookie.getName())) {
usernameCookie = cookie.getValue(); // 得到cookie的用户名
}
}
}
System.out.println("@@@@@@@@@@@@@@@@@@@@页面建立连接!");
String flag = request.getParameter("flag");
//判断是否进行登录验证,如果flag为1时进行登录验证
if (flag != null && flag.trim().equals("1"))
{ //登录控制对象
Login log = new Login();
String username = request.getParameterValues("user")[0].trim();
String password = request.getParameterValues("pass")[0].trim();
if (log.isLogin(username,password))
{
//插入日志表
XtrzFormBean.insertXtrz(XtrzConstant.LOGIN,username, "", "");
session.setAttribute("user",username);
//设置cookie
Cookie usercookie=new Cookie("usercookie",username);
usercookie.setMaxAge(24*60*60);
//usercookie.setPath("/");
//usercookie.setDomain(request.getServerName());
response.addCookie(usercookie);

response.sendRedirect("index.jsp");
return;
} else {
errorMessage = log.getMessage();
}
}
else
{
errorMessage = "您还没有尝试登录.";
}

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html> <head>

<title>欢迎登录XXXXXXXX管理系统</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 href="css/global.css" rel="stylesheet" type="text/css" />
<link href="css/login.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" >
function doLogin(){
document.forms[0].flag.value = "1";
document.forms[0].submit();
alert("提交登陆!")
}
</script>
</head>

<body>
<div class="login">
<form action="login.jsp" method="post" name="form1">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="span1">用户</td>
<td ><input type="text" name="user" id="user" value="<%=usernameCookie %>"/></td>
</tr>
<tr>
<td class="span1">密码</td>
<td><input type="password" name="pass" id="pass" /></td>
</tr>
</table>
<ul>
<li><a class="btnLog" href="#" style="cursor:hand" onclick="doLogin()">登录</a></li>
<li><a class="btnReset" href="#" style="cursor:hand" onclick="document.forms[0].reset()">重置</a></li>
</ul>
<%= errorMessage%><input type="hidden" name="flag" id="flag"/>
</form>
</div>
</body>
</html>


报错为:
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /login.jsp at line 24

21: //判断是否进行登录验证,如果flag为1时进行登录验证
22: if (flag != null && flag.trim().equals("1"))
23: { //登录控制对象
24: Login log = new Login();
25: String username = request.getParameterValues("user")[0].trim();
26: String password = request.getParameterValues("pass")[0].trim();
27: if (log.isLogin(username,password))


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:515)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:426)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.NullPointerException
com.gt.login.Login.<init>(Login.java:51)
org.apache.jsp.login_jsp._jspService(login_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.10

高手指点下 感激不尽!
...全文
125 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ai593423625 2010-08-12
  • 打赏
  • 举报
回复
debug 一下···
hanshuihu 2010-08-12
  • 打赏
  • 举报
回复
上面那个login 的代码 为什么我写的system.out.println 后台都不打印呢?
hanshuihu 2010-08-12
  • 打赏
  • 举报
回复
package com.gt.login;

/**
* 用户登录控制类
* 控制用户登录,包括
* 1,验证用户登录名,密码
* 2,输出控制台提示消息
* 3, 获取用户信息
*
* @author gaofeiyun
*
*/

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.gt.util.db.ConnectionPool;

public class Login {
private int count;
private Connection con;
private Statement stmt;
private ResultSet rs;
private ConnectionPool db;

private String message;

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
/**
* 构造方法
*/
public Login(){
count = 0;
con = null;
stmt = null;
rs = null;

db = new ConnectionPool("");
con = db.getConnection();
try
{
System.out.println("@@@@@@@@@@@@@@@@@@@@建立连接!");
stmt = con.createStatement(1005, 1007);
}
catch(SQLException e)
{
System.out.println(".....Exception:......."+e);
}
}

/**
* 用户登录校验
* @param username 用户名
* @param password 密码
* @return
* boolean
* TODO
*/
public boolean isLogin(String username, String password){
boolean loginFlag = false;
if(username.equals("") || username==null){
message = LoginMessage.message_username_null;
}else if(password.equals("") || password==null){
message = LoginMessage.message_password_null;
}else{
//构建查询语句
StringBuffer bufLoginCheck = new StringBuffer();
bufLoginCheck.append(" select * from jjd_xtry where 1=1 ");
bufLoginCheck.append(" and dlzh = '");
bufLoginCheck.append(username.trim());
bufLoginCheck.append("' and dlmm = '");
bufLoginCheck.append(password.trim());
bufLoginCheck.append("'");
try {
rs = stmt.executeQuery(bufLoginCheck.toString());
rs.last();
count = rs.getRow();
if(count < 0||count==0){
message = LoginMessage.message_login_error;
}else{
message = "";
loginFlag = true;
}
}catch(SQLException e){
loginFlag = false;
message = LoginMessage.message_sys_error;
System.out.println(".....Exception:......."+e);
}finally{
try{
rs.close();
stmt.close();
con.close();
con = null;
}catch(SQLException se){
loginFlag = false;
message = LoginMessage.message_sys_error;
System.out.println(".....Exception:......."+se);
}
}
}
return loginFlag;//UTIL.toChinese1(message);
}

}
hanshuihu 2010-08-12
  • 打赏
  • 举报
回复
好像没用。。。。。还是那个问题 他提示好像是24行有问题
im110 2010-08-12
  • 打赏
  • 举报
回复
java.lang.NullPointerException
com.gt.login.Login.<init>(Login.java:51)
说明你的Login类的第51行引用了一个空类型。
学习Java中 2010-08-12
  • 打赏
  • 举报
回复
Login 对象导入了吗
crazylaa 2010-08-12
  • 打赏
  • 举报
回复
root cause

java.lang.NullPointerException
com.gt.login.Login.<init>(Login.java:51)
org.apache.jsp.login_jsp._jspService(login_jsp.java:84)


空指针,参数没取到
String username = request.getParameterValues("user")[0].trim();
String password = request.getParameterValues("pass")[0].trim();

直接用
request.getParameter(...
shishi
hanshuihu 2010-08-12
  • 打赏
  • 举报
回复
jar包位置的问题放置在tomcat的lib下面问题解决

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧