主页
<%@ page contentType="text/html; charset=GB2312" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <title>登陆成功</title>
</head><body>
<s:form action="Chengxu1.action" method="post">
 <s:textfield name="username" label="用户名"/>
  <s:password name="password1" label="密码"/>
<s:password name="password2" label="再次输入密码"/>
<s:textfield name="work" label="职业"/>
    <s:submit value="注册"/>
</s:form>
</body>
</html>
跳转页
<%@ page contentType="text/html; charset=GB2312" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <title>登陆成功</title>
</head><body>
    注册成功!<br>
    您的基本信息如下:<br>
    用户名:<s:property value="username" /><br>
    密     码:<s:property value="password"/><br>
    职     业:<s:property value="work"/><br>
  </body></html>
action
package package1;import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;public class Chengxu1 extends ActionSupport {

private String username;
private String password;
private String password2;
private String work;

public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getpassword() {
return password;
}
public void setPwd(String password) {
this.password = password;
}
public String getpassword2() {
return password2;
}
public void setConfirm(String password2) {
this.password2 = password2;
}
public String getwork() {
return work;
}
public void setJob(String work) {
this.work = work;
}

public String execute() throws Exception {
if (this.work == null || "".equals(this.work))
this.setJob("无");
return SUCCESS;
}

@Override
public void validate() {
if (this.username == null || "".equals(this.username))
this.addFieldError("username", "用户名不能为空");
if (this.password == null || "".equals(this.password))
this.addFieldError("password", "密码不能为空");
if (this.password2 == null || "".equals(this.password2))
this.addFieldError("password2", "没有重复输入密码");
if (!this.password2.equals(this.password2)){
this.addFieldError("password2", "两次输入的密码不一致");
}
}
}
配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="package1" extends="struts-default">
<action name="Chengxu1" class="package1.Chengxu1">
<result>Chengxu2.jsp</result>
</action>
</package>
</struts>
一个很小的项目老出现 The server encountered an internal error () that prevented it from fulfilling this request,很让我头疼

解决方案 »

  1.   

    把<s:password name="password1" label="密码"/>中的“password1”改为“password”,或者将public void setPwd(String password)方法中的参数password改为password1应该就行了,两种方法选择一种即可。两个变量名的名字应该是相同的。
      

  2.   

    同楼上。
    这位兄弟写代码的时候要细心点,if (!this.password2.equals(this.password2)){
    this.addFieldError("password2", "两次输入的密码不一致");
    }这里也很明显有问题,你用password2和password2比较都会返回ture的。
      

  3.   

    谢谢,我已经改过来了,但是还是有错误
    type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: java.lang.NullPointerException
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)
      

  4.   

    重启tomcat,然后再把你的全部错误贴出来看看
      

  5.   

    private String username;
    private String password1;
    private String password2;
    private String work;get set方法