这是一个名为
的动作调用的JSP页面<body>
hi welcome to
<s:property value="username" />
<s:submit action="allrecords" value="All Records Show"></s:submit>
</body>
在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>
答案 0 :(得分:0)
你说提交行动无效。我想你有submit
标签不起作用。将action属性与submit标记一起使用的问题。默认情况下,此功能已禁用。您可以尝试删除操作属性并将表单映射到操作。
<s:form action="allrecords">
...
<s:submit value="All Records Show"/>
</s:form>