简体   繁体   English

提交按钮操作在Struts2框架中不起作用

[英]submit button action not working in Struts2 framework

this is JSP page where action call get called 这是调用操作调用的JSP页面

<body>      
 hi welcome to
 <s:property value="username" />
 <s:submit action="allrecords" value="All Records Show"></s:submit>                
</body>

List item 项目清单

In struts xml: 在struts xml中:

<struts>

   <constant name="struts.mapper.action.prefix.enabled" value="true" />

   <constant name="struts.devMode" value="true" />
   <constant name="struts.enable.DynamicMethodInvocation" value="true" />
   <constant name="struts.custom.i18n.resources"             value="ApplicationResources"/> 

  <include file="loginfirst.xml"></include>

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

    <action name="reguser">
        <result>/login.jsp</result>
    </action>

    <action name="loginprocess" class="com.org.struts.Loginprocess">

        <result name="success">/success.jsp
        </result>
        <result name="error">/login.jsp
        </result>
        <result name="input">/login.jsp</result>

    </action>

    <action name="allrecords" class="com.org.struts.FetchRecords">

        <result name="success">/allrecords.jsp
        </result>
    </action>



  </package>


  <package name="default" namespace="/legends" extends="struts-default">
    <action name="gettutorial" class="com.org.struts.Tutorial">

        <result name="success">/success.jsp
        </result>
        <result name="error">/error.jsp
        </result>

    </action>

    <action name="addtutorial" class="com.org.struts.Tutorial"
        method="addmethod">

        <result name="success">/success.jsp
        </result>
        <result name="error">/error.jsp
        </result>

    </action>

    </package>
</struts>

here's action class 这是动作课

public class FetchRecords extends ActionSupport   {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    /**
     * 
     */
    ArrayList<User> list=new ArrayList<User>();  

    public ArrayList<User> getList() {  
        return list;  
    }  
    public void setList(ArrayList<User> list) {  
        this.list = list;  
    }  
    public String execute(){  
     try{  
      Class.forName("com.mysql.jdbc.Driver");  
      Connection con=DriverManager.getConnection(  
              "jdbc:mysql://localhost:3306/strutssampleform", "root", "");  

      PreparedStatement ps=con.prepareStatement("select * from USER_DETAIL");  
      ResultSet rs=ps.executeQuery();  

      while(rs.next()){  
       User user=new User();  
       user.setFirstName(rs.getString(1));  
       user.setLastName(rs.getString(2));  
       user.setUsername(rs.getString(3));  
       user.setEmailid(rs.getString(5));  
       list.add(user);  
      }  

      con.close();  
     }catch(Exception e){e.printStackTrace();}  

     return "success";  
    }

} 

List item 项目清单

allrecords display jsp allrecords显示jsp

<s:iterator  value="list">  
<fieldset>  
<s:property value="firstName"/><br/>  
<s:property value="lastName"/><br/>  
<s:property value="username"/><br/>  
<s:property value="emailid"/><br/>  
</fieldset>  
</s:iterator>

You said that submit action is not working. 您说提交操作无效。 I suppose that you have a submit tag that doesn't work. 我想您有一个submit标签不起作用。 The problem that you use the action attribute with the submit tag. 您将动作属性与Submit标记一起使用的问题。 By default this feature is disabled. 默认情况下,此功能处于禁用状态。 You may try to remove the action attribute and map a form to the action instead. 您可以尝试删除动作属性,然后将表单映射到该动作。

<s:form action="allrecords">
 ...
 <s:submit value="All Records Show"/>
</s:form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM