错误 - >找不到指定操作的配置

时间:2013-09-17 13:46:26

标签: java hibernate struts2 tiles

其实我正在尝试Struts2 + tiles + spring3 + hibernate的组合。在这里,我无法将POJO类的值放到数据库中。 并显示此错误

**Sep 17, 2013 7:12:12 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 17519 ms
2013-09-17 19:12:14 WARN  ServletUrlRenderer:45 - No configuration found for the specified action: 'gotoStrutsRegistration' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
2013-09-17 19:12:14 WARN  ServletUrlRenderer:45 - No configuration found for the specified action: 'gotoStrutsRegistration' in namespace: ''. Form action defaulting to 'action' attribute's literal value.**

这是我在运行以下代码时遇到的错误,

的web.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">

<struts>
    <constant name="sturts.enable.DynamicMethodinvocation" value="false" 
        /> <constant name="struts.devMode" value="true" /> <constant name="struts.custom.i18n.resources" 
        value="ApplicationResources" />
    <package name="default" extends="struts-default" namespace="">
        <result-types>
            <result-type name="tiles"
                class="org.apache.struts2.views.tiles.TilesResult" />
        </result-types>

        <action name="*userRegistration" method="{1}" class="userRegistration">
            <result name="success" type="tiles">isas.user.registration</result>
            <result name="error" type="tiles">isas.errorPage</result>
            <result name="input" type="tiles">isas.user.registration</result>
        </action>
    </package>
</struts>

struts.xml中

<struts>
    <constant name="sturts.enable.DynamicMethodinvocation" value="false" 
        /> <constant name="struts.devMode" value="true" /> <constant name="struts.custom.i18n.resources" 
        value="ApplicationResources" />
    <package name="default" extends="struts-default" >
        <result-types>
            <result-type name="tiles"
                class="org.apache.struts2.views.tiles.TilesResult" />
        </result-types>

        <action name="userRegistration" method="saveUserDetails" class="userRegistration">
            <result name="success" type="tiles">isas.user.registration</result>
            <result name="error" type="tiles">isas.errorPage</result>
            <result name="input" type="tiles">isas.user.registration</result>
        </action>

    </package>
</struts>

Action.java

public class RegistrationAction {
//user details attributes
private int user_Id;
private String first_Name;
private String last_Name;
private String emailid;
private String passWord;
private String Gender;
private int dateofbirth;
private int phoneNo;
private int experience;
private String resume;
//user address attributes
private String addr_line1;
private String addr_line2;
private String addr_line3;
private String city;
private int zipcode;
private String state;
private String country;
private int address_Id;
Session session=null;
public int getExperience() {
    return experience;
}
public void setExperience(int experience) {
    this.experience = experience;
}
public int getUser_Id() {
    return user_Id;
}
public void setUser_Id(int user_Id) {
    this.user_Id = user_Id;
}
public String getFirst_Name() {
    return first_Name;
}
public void setFirst_Name(String first_Name) {
    this.first_Name = first_Name;
}
public String getLast_Name() {
    return last_Name;
}
public void setLast_Name(String last_Name) {
    this.last_Name = last_Name;
}
public String getEmailid() {
    return emailid;
}
public void setEmailid(String emailid) {
    this.emailid = emailid;
}
public String getPassWord() {
    return passWord;
}
public void setPassWord(String passWord) {
    this.passWord = passWord;
}
public String getGender() {
    return Gender;
}
public void setGender(String gender) {
    Gender = gender;
}
public String getResume() {
    return resume;
}
public void setResume(String resume) {
    this.resume = resume;
}
public int getDateofbirth() {
    return dateofbirth;
}
public void setDateofbirth(int dateofbirth) {
    this.dateofbirth = dateofbirth;
}
public int getPhoneNo() {
    return phoneNo;
}
public void setPhoneNo(int phoneNo) {
    this.phoneNo = phoneNo;
}
public String getAddr_line1() {
    return addr_line1;
}
public void setAddr_line1(String addr_line1) {
    this.addr_line1 = addr_line1;
}
public String getAddr_line2() {
    return addr_line2;
}
public void setAddr_line2(String addr_line2) {
    this.addr_line2 = addr_line2;
}
public String getAddr_line3() {
    return addr_line3;
}
public void setAddr_line3(String addr_line3) {
    this.addr_line3 = addr_line3;
}
public String getCity() {
    return city;
}
public void setCity(String city) {
    this.city = city;
}
public int getZipcode() {
    return zipcode;
}
public void setZipcode(int zipcode) {
    this.zipcode = zipcode;
}
public String getState() {
    return state;
}
public void setState(String state) {
    this.state = state;
}
public String getCountry() {
    return country;
}
public void setCountry(String country) {
    this.country = country;
}
@SuppressWarnings({ "unused", "unchecked" })
public String saveUserDetails() throws Exception{
    String forward="success";
    try{
    ApplicationContext factory = new ClassPathXmlApplicationContext("hibernate-spring.xml");
    UserDetails user1=new UserDetails();//create an object for the user
    //These are the user details
    user1.setUser_id(getUser_Id());
    user1.setFirst_name(getFirst_Name());
    user1.setLast_name(getLast_Name());
    user1.setEmail(getEmailid());
    user1.setPassword(getPassWord());
    user1.setGender(getGender());
    user1.setDob(getDateofbirth());
    user1.setPhone(getPhoneNo());
    user1.setResume(getResume());
    user1.setExperience(getExperience());
    //These are the address details
    UserAddress useraddress=new UserAddress();
    useraddress.setAddress_id(getAddress_Id());
    useraddress.setAddr_line_1(getAddr_line1());
    useraddress.setAddr_line_2(getAddr_line2());
    useraddress.setAddr_line_3(getAddr_line3());
    useraddress.setCity(getCity());
    useraddress.setZipcode(getZipcode());
    useraddress.setState(getState());
    useraddress.setCountry(getCountry());
  //  useraddress.setUser_det_id(getUser_Id());
    //Now Create a Set

    Set enter_addr=new HashSet(0);
    enter_addr.add(useraddress);
    user1.setAddress(enter_addr);
    UserRegistrationDao studentDao = (UserRegistrationDao)factory.getBean("studentDao");
    session.beginTransaction();
    UserDetails stuResult = studentDao.saveUserRegistration(user1);
    UserAddress addResult=studentDao.saveUserAddress(useraddress);
    session.saveOrUpdate(stuResult);
    session.saveOrUpdate(addResult);
    session.getTransaction().commit();
    }
    catch(Exception e)
    {
        return "error";
    }

    return forward;
}
public int getAddress_Id() {
    return address_Id;
}
public void setAddress_Id(int address_Id) {
    this.address_Id = address_Id;
}
}

1 个答案:

答案 0 :(得分:0)

嗯,只是你需要将这个名称空间Tag添加到包中的starts.xml中,就像这样。

<package name="default" extends="struts-default" namespace="/first">

同样的方式你必须将它映射到Jsp页面。

<s:form namespace="/first" action="getservlet" method="Post">

这样它就会在struts.xml中找到配置。