📄 queryaction.java
字号:
package prj2_1;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import dao.StudentDao;
//Action:负责接受ActionForm的数据,处理
//1:必须继承org.apache.struts.action.Action
//2:重写execute方法来处理业务逻辑
//3:将这个类在配置文件中注册
public class QueryAction extends Action{
public QueryAction(){
System.out.println("QueryAction构造函数");
}
//ActionForward:封装了跳转目标的路径
//mapping:访问配置文件
//form:传过来的ActionForm对象
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
QueryForm queryForm = (QueryForm)form;
String sname = queryForm.getSname();
//String sname = request.getParameter("sname");
sname = new String(sname.getBytes("ISO-8859-1"));
StudentDao studentDao = new StudentDao();
ArrayList stus = studentDao.queryStuByName(sname);
request.setAttribute("stus", stus);
//跳转
//ActionForward af = new ActionForward("/queryResult.jsp");
ActionForward af = mapping.findForward("RESULT");
return af;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -