没有为动作net.action.RegisterAction和结果输入定义结果

时间:2013-01-07 06:34:32

标签: java struts

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

Register.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和结果输入定义结果

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

1 个答案:

答案 0 :(得分: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执行之前发生Validation错误 要查看此验证错误,请在操作中添加名称为input的结果。

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