标题:【求助】struts做的登陆出错
只看楼主
沉墨小菜鸟
Rank: 2
等 级:论坛游民
帖 子:16
专家分:26
注 册:2009-11-23
结帖率:100%
 问题点数:0 回复次数:1 
【求助】struts做的登陆出错
===============报错 =======================
javax.servlet.ServletException: java.lang.NullPointerException
    org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.NullPointerException
    com.movie.struts.action.LoginAction.execute(LoginAction.java:46)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    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.13 logs.

=====================loginAction.jave页面==============
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.movie.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import biz.UserBiz;
import biz.impl.UserBizImpl;
import com.movie.struts.form.LoginForm;
import entity.*;
/**
* MyEclipse Struts
* Creation date: 11-22-2009
*
* XDoclet definition:
* @struts.action path="/login" name="loginForm" parameter="useroperation" scope="request" validate="true"
* @struts.action-forward name="succsee" path="movielist.jsp"
* @struts.action-forward name="error" path="error.jsp"
*/
public class LoginAction extends DispatchAction {
/*
  * Generated Methods
  */
/**
  * Method execute
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return ActionForward
  */
public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
  LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
  
  String name =loginForm.getUser().getUsername();
  String pwd =loginForm.getUser().getPassword();
  UserBiz userBiz = new UserBizImpl();
  System.out.println(name);
  System.out.println(pwd);
   int num = userBiz.login(name, pwd) ;
  if(num>0)
  {
   return mapping.findForward("movielist");
  }else{
   return mapping.findForward("error");
  }
}
}



=========================loginForm.java页面==============
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.movie.struts.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import entity.User;
/**
* MyEclipse Struts
* Creation date: 11-22-2009
*
* XDoclet definition:
* @struts.form name="loginForm"
*/
public class LoginForm extends ActionForm {
/*
  * Generated fields
  */
/** user property */
private User user;
/*
  * Generated Methods
  */
/**
  * Method validate
  * @param mapping
  * @param request
  * @return ActionErrors
  */
public ActionErrors validate(ActionMapping mapping,
   HttpServletRequest request) {
  // TODO Auto-generated method stub
  return null;
}
/**
  * Method reset
  * @param mapping
  * @param request
  */
public void reset(ActionMapping mapping, HttpServletRequest request) {
  // TODO Auto-generated method stub
}
/**
  * Returns the user.
  * @return User
  */
public User getUser() {
  return user;
}
/**
  * Set the user.
  * @param user The user to set
  */
public void setUser(User user) {
  this.user = user;
}
}






===============struts-config.xml===============
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.
<struts-config>
  <data-sources />
  <form-beans >
    <form-bean name="loginForm" type="com.movie.struts.form.LoginForm" />
  </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="loginForm"
      name="loginForm"
      path="/login"
      scope="request"
      type="com.movie.struts.action.LoginAction">
      <forward name="succsee" path="/movielist.jsp" />
      <forward name="error" path="/error.jsp" />
    </action>
  </action-mappings>
  <message-resources parameter="com.movie.struts.ApplicationResources" />
</struts-config>
======================login.jsp============================
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://struts. prefix="bean"%>
<%@ taglib uri="http://struts. prefix="html"%>

<html>
<head>
  <title>JSP for LoginForm form</title>
</head>
<body>
  <form action="login.do" method="post">
  <table align="center" valign="middle">
  <tr>
  <td>用户名:</td>
  <td><input type="text" name="username"></td>
  </tr>
  <tr>
  <td>密码:</td>
  <td><input type="password" name="pwd"></td>
  </tr>
  <tr>
  <td></td>
  <td><input type="submit" value="登陆" class="textLine"> <input type="reset" value="重置"></td>
  </tr>
  </table>
  </form>
</body>
</html>
=================================================


[ 本帖最后由 沉墨小菜鸟 于 2009-11-23 14:07 编辑 ]
搜索更多相关主题的帖子: 登陆 struts 
2009-11-23 13:44
沉墨小菜鸟
Rank: 2
等 级:论坛游民
帖 子:16
专家分:26
注 册:2009-11-23
得分:0 
已解决
2009-11-23 15:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-293062-1-1.html




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

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