Struts中的Action\ActionForm的编写
QueryForm.java(Struts_Method.QueryForm)
import org.apache.struts.action.ActionForm;
public class QueryForm extends ActionForm {
private String sname;
public String getsname{
return sname;
}
public void setsname(String sname){
this.sname=sname;
}
}
一:QueryAction.java(Struts_Method.QueryAction.java)
public class QueryAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception
{
QueryForm myform=(QueryForm)form;
String sname=myform.getSname();
sname=new String(sname.getBytes("ISO-8859-1"));
UsersDAO user=new UsersDAO();
ArrayList users=user.QueryByName(sname);
request.setAtrribute("users",users);
import org.apache.struts.action.ActionForm;
public class QueryForm extends ActionForm {
private String sname;
public String getsname{
return sname;
}
public void setsname(String sname){
this.sname=sname;
}
}
一:QueryAction.java(Struts_Method.QueryAction.java)
public class QueryAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception
{
QueryForm myform=(QueryForm)form;
String sname=myform.getSname();
sname=new String(sname.getBytes("ISO-8859-1"));
UsersDAO user=new UsersDAO();
ArrayList users=user.QueryByName(sname);
request.setAtrribute("users",users);
ActionForward af=new ActionForward("/Result.jsp");
<!--根据Struts-config.xml里面定义的全局、局部跳转的参数值跳转-->
ActionForward af=mapping.findForward("result");
return af;
}
}
二、Struts-config.xml
<!--QueryForm注册-->
<form-beans>
<form-bean name="queryform" type="Struts_Method.QueryForm">
</form-bean>
</form-beans>
<!--QueryAction注册-->
<action-mappings>
<action name="queryform" path="/query" type="Struts_Method.QueryAction">
<!--定义局部跳转,只针对该Action-->
<forward name="result" path="/queryResult.jsp"></forward>
</action>
</action-mappings>
<!--定义全局跳转-->
<global-forwards>
<forward name="result" path="/queryResult.jsp"></forward>
</global-forwards>
三、Query.jsp
<form action="/query.do" method="post">
</form>