?? 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 + -