0
<s:form action="register.action">
    <fieldset>
        <div class="head">Registration</div>
        <hr>
        <div>
            <label>Name</label>
            <input type="text" name="username"/>
        </div>
        <div>
            <label>User Id</label>
            <input type="text" name="userid"/>
        </div>
        <div>
            <label>Password</label>
            <input type="password" name="password"/>
        </div>
        <div>
            <label>Email</label>
            <input type="text" name="email"/>
        </div>
        <div>
            <label>City</label>
            <input type="text" name="city"/>
        </div>
        <div>
            <label>Locality</label>
            <input type="text" name="Locality"/>
        </div>
        <hr>
        <div class="checkbox">
            <input type="checkbox" class="check"><div class="text">I confirm that I am 18 years or older & eligible to register and post ads</div>
        </div>
        <div class="checkbox1">
            <input type="checkbox" checked="checked" class="check"><div class="text">Uncheck this box, if you do not wish to be intimated about special offers and new features.</div>
        </div>
        <div class="terms">By clicking " Register ", you're agreeing to our <a href="">Terms of Use & Privacy Policy.</a></div>
        <div>
            <button type="reset" id="reset">Reset</button>
            <s:submit value="Register" cssClass="submit-go" />
        </div>
    </fieldset>
</s:form>

注册.java

package net.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="Register")
public class Register {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column(name="username")
private String username;
@Column(name="userid")
private String userid;
@Column(name="password")
private String password;
@Column(name="email")
private String email;
@Column(name="city")
private String city;
@Column(name="locality")
private String locality;
public Register() {
    super();
    // TODO Auto-generated constructor stub
}
public Register(int id, String username, String userid, String password,
        String email, String city, String locality) {
    super();
    this.id = id;
    this.username = username;
    this.userid = userid;
    this.password = password;
    this.email = email;
    this.city = city;
    this.locality = locality;
}
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getUsername() {
    return username;
}
public void setUsername(String username) {
    this.username = username;
}
public String getUserid() {
    return userid;
}
public void setUserid(String userid) {
    this.userid = userid;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}
public String getEmail() {
    return email;
}
public void setEmail(String email) {
    this.email = email;
}
public String getCity() {
    return city;
}
public void setCity(String city) {
    this.city = city;
}
public String getLocality() {
    return locality;
}
public void setLocality(String locality) {
    this.locality = locality;
}
}

注册动作类

 package net.action;

 import java.util.ArrayList;
 import java.util.List;

 import javax.persistence.Column;

 import net.controller.Manager;
 import net.model.Register;

 import com.opensymphony.xwork2.Action;
 import com.opensymphony.xwork2.ActionSupport;

 public class RegisterAction extends ActionSupport{

/**
 * 
 */
private static final long serialVersionUID = 1L;

private String username;

private String userid;

private String password;

private String email;

private String city;

private String locality;

private List<Register> registerList;

public RegisterAction() {
    super();
    // TODO Auto-generated constructor stub
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getUserid() {
    return userid;
}

public void setUserid(String userid) {
    this.userid = userid;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

public String getLocality() {
    return locality;
}

public void setLocality(String locality) {
    this.locality = locality;
}

public List<Register> getRegisterList() {
    return registerList;
}

public void setRegisterList(List<Register> registerList) {
    this.registerList = registerList;
}

public String execute() throws Exception {
    Register registerUser = new Register();
    String result = "error";
    List<Register> getUserdetails = new ArrayList<Register>();
    registerUser.setUsername(username);
    registerUser.setUserid(userid);
    registerUser.setPassword(password);
    registerUser.setEmail(email);
    registerUser.setCity(city);
    registerUser.setLocality(locality);

    if(Manager.adduser(registerUser)){
        getUserdetails = Manager.registerlist();
        return Action.SUCCESS;
    }
    return result;
}

}

struts.xml

   <?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">

<constant name="struts.devMode" value="false"/>

 <package name="default" extends="struts-default">

 <action name="postad" method="execute" class="net.action.PostAction" >
        <result name="success" >viewpost.jsp</result>
        <result name="error" >postad.jsp</result>
    </action>

  <action name="register" class="net.action.RegisterAction" method="execute">
    <result name="SUCCESS">home.jsp</result>
    <result name="error">register.jsp</result>
  </action>
 </package>

我正在struts2-Hibernate上做一个示例项目,当我点击提交按钮时,我发现了一个错误

HTTP 状态 404 - 没有为动作 net.action.RegisterAction 和结果输入定义结果

请帮我?这里有什么错误?

4

1 回答 1

0

首先请原谅我糟糕的英语。在您的 jsp 上,尝试使用定义的 struts 标签而不是 html 元素,struts 标签提供更多信息以防发生错误。还尝试添加标签 actionError 和 actionMessage 以可视化一些错误。

<s:form action="register.action">
   <s:textfield name="username" label="Name" />
   <s:textfield name="userid" label="User Id" />
   <s:password name="password" label="Password" />
   <s:submit value="Register" cssClass="submit-go" />
   <s:actionerror label="ERRORS" />
   <s:actionmessage label="MESSAGES" />
</s:form>

HTTP 状态 404 - 没有为动作 net.action.RegisterAction 和结果输入定义结果

此错误大部分时间由 de Workflow Interceptor 生成,每当在操作执行之前发生验证错误时,要查看此验证错误,请在您的操作上添加名称输入的结果。

<action name="register" class="net.action.RegisterAction" method="execute">
  <result name="SUCCESS">home.jsp</result>
  <result name="error">register.jsp</result>
  <result name="input">register.jsp</result>
</action>
于 2013-06-27T19:04:22.547 回答