this is JSP page where action call get called
<body>
hi welcome to
<s:property value="username" />
<s:submit action="allrecords" value="All Records Show"></s:submit>
</body>
In 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>
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";
}
}
<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. The problem that you use the action attribute with the submit tag. 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.