📄 indexaction.java
字号:
package javafish.web.actions;
import javafish.util.Constant;
import javafish.util.PageList;
import javafish.util.Pages;
import javafish.web.forms.IndexForm;
import javafish.model.JavaFish;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* @author longjiang
* @version 1.0
* 这个类是具体的Action类,在这个类中调用业务对象
*/
public class IndexAction extends BaseAction
{
public ActionForward execute(ActionMapping mapping,
ActionForm form, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception
{
String forward=null; //定义一个程序转向字符
ActionErrors errors =new ActionErrors(); //生成错误提示对象
IndexForm actionForm=(IndexForm)form; //生成对应的ActionForm对象
String username=actionForm.getUsername(); //读取表单中的username属性
String password=actionForm.getPassword(); //读取表单中的password属性
JavaFish jf=this.getIJavaFishService().findByUserNamePassWord(username,password);
if((!username.equals(jf.getUsername()))||(!password.equals(jf.getPassword())))
{
return mapping.getInputForward();
}
else
{
Pages pages = new Pages(httpServletRequest);
pages.setPage(actionForm.getPage());
pages.setPerPageNum(3);
if (actionForm.getT() > 0) {
pages.setTotals(actionForm.getT());
}
pages.setFileName("indexAction"+Constant.FILEPREFIX);
pages.setStyle(1);
PageList pl = getIJavaFishService().findJavaFishInList(actionForm.getOrderby(),actionForm.getAscordesc(), pages);
httpServletRequest.setAttribute("pl", pl);
forward=Constant.SUCESS;
}
if (actionForm.getAction().equals("edit")) {
JavaFish jf1 = this.getIJavaFishService().getJavaFish(actionForm.getId());
if (jf1!= null) {
actionForm.setAction("editdo");
actionForm.setUsername(jf1.getUsername());
actionForm.setPassword(jf1.getPassword());
actionForm.setId(jf1.getId().longValue());
return mapping.findForward("adduser");
}
System.out.println("====error.jsp====");
}
if (actionForm.getAction().equals("editdo")) {
JavaFish jf1 = this.getIJavaFishService().getJavaFish(actionForm.getId());
if (jf1!= null) {
jf1.setUsername(jf1.getUsername());
jf1.setPassword(jf1.getPassword());
jf1=this.getIJavaFishService().saveJavaFish(jf1);
}
if (jf1 == null) {
System.out.println("========error.jsp========");
}
return mapping.findForward("index.jsp");
}
if (actionForm.getAction().equals("new")) {
actionForm.setAction("add");
return mapping.findForward("adduser");
}
if (actionForm.getAction().equals("add")) {
JavaFish jf3=new JavaFish();
;
jf3.setUsername(actionForm.getUsername());
jf3.setPassword(actionForm.getPassword());
jf3=this.getIJavaFishService().saveJavaFish(jf3);
if(jf3==null){
System.out.println("========添加数据失败=========");
}
return mapping.findForward("index.jsp");
}
if (actionForm.getAction().equals("del")) {
System.out.println(actionForm.getId());
this.getIJavaFishService().removeJavaFish(actionForm.getId());
return mapping.findForward("failed");
}
return(mapping.findForward(forward));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -