我个人觉得已经没有错误了,实在不知道为什么还是会报500的错误。代码如下:
一,login.jsp
<%@ page contentType="text/html;charset=GBK" language="java" %>
<body vLink="#006666" link="#003366" bgcolor="#E0F0F8">
<form action="login.do" method="post">
用户名:<input size="15" name="name"><p>
密  码:<input type="password" size="15" name="psw"><p>
<a href="regist.do">新用户注册</a>
<a href="login.do">AAAAAAAAAAAA</a>
<input type="submit" value="登录">
</form>
</body>
二,right.jsp
<%@ page language="java" contentType="text/html; charset=Shift_JIS"
    pageEncoding="Shift_JIS"%>
<%@ page import = "classmate.*" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>Insert title here</title>
</head>
<body>
<%
UserForm formBean1 =(UserForm)request.getAttribute("formBean1");
if(formBean1 != null && formBean1.getName() != null){
%>
Welcome,<%= formBean1.getName()%>!!!!
<%
}else{
%>
Who are you!??
<%
}
%>
<BR>
<a href="login.jsp">Please login</a>
<a href="regist.jsp">Please regist</a>
</body>
</html>
三,web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app><!--Action Servlet Configuration -->
<servlet>
<servlet-name>actionServlet</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet><!--Action Servlet Mapping-->
<servlet-mapping>
<servlet-name>actionServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping><!--The Welcome File List-->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list></web-app>
四,struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config><form-beans>
<form-bean name="formBean1" Type="classmate.UserForm" />
</form-beans><global-forwards>
<forward name="failed" path="/error.jsp"/>
<forward name="successed" path="/right.jsp"/>
</global-forwards><action-mappings>
<action path="/login" type="classmate.LoginAction" name="formBean1" scope="request" input="/login.jsp"/>
<action path="/regist" forward="/regist.jsp"/> 
</action-mappings></struts-config>

解决方案 »

  1.   

    五,LoginAction.java
    package classmate;import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;public final class LoginAction extends Action{
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{

    UserForm userform = (UserForm) form;

    String name = userform.getName();
    String psw = userform.getPsw();

    if("tom".equals(name) && "hi".equals(psw)){
    return mapping.findForward("successed");
    }else{
    return mapping.findForward("failed");
    }
    }
    }
    六,UserForm.java
    package classmate;import org.apache.struts.action.ActionForm;public class UserForm extends ActionForm{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private String name = null;
    private String psw = null;
    public UserForm(){}

    public void setName(String name){
    this.name = name;
    } public void setPsw(String psw){
    this.psw = psw;
    }

    public String getName(){
    return name;
    }

    public String getPsw(){
    return psw;
    }
    }代码是参照《Eclise开发入门与项目实践》写的,但是好像运行不起来。
    只要点击login.jsp中的登陆按钮,会报http500错误,java.lang.NullPointerException。
    我弄了3天了,也没进展,请大家帮忙看看吧。开发环境是Eclipse3.1和tomcat5.0,Struts1.2.9。
      

  2.   

    UserForm formBean1 =(UserForm)request.getAttribute("formBean1");???
    你在什么地方存了formBean1了呢
      

  3.   

    NullPointerException空指针异常
    肯定是什么地方调用了空指针了
      

  4.   

    in the action:if("tom".equals(name) && "hi".equals(psw)){
    //Please notice the following
        request.setAttribute("formbean1", userform);
    return mapping.findForward("successed");
    }else{
    return mapping.findForward("failed");
    }
    }
      

  5.   

    谢谢大家,我加了request.setAttribute("formBean1", userform);但是运行仍然报500错误。
    Parse Error at line 8 column 58: Attribute "type" is required and must be specified for element type "form-bean".在struts-config文件里的这句,难道有什么错误吗?
    <form-beans>
    <form-bean name="formBean1" Type="classmate.UserForm" />
    </form-beans>
      

  6.   

    谢谢大家帮助,原来是大小写的原因。
    <form-bean name="formBean1" Type="classmate.UserForm" />
    中的Type应该改为type,谢谢大家,谢谢大家。
      

  7.   

    to 帮助我的两位朋友:yangjiyue(yangjiyue) ,syhan(藏书人) 
    <action path="/login" type="classmate.LoginAction" name="formBean1" scope="request" input="/login.jsp"/>这句配置好像可以完成request.setAttribute("formbean1", userform)的功能。