?? helloaction.java
字號(hào):
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package hello;
import org.apache.struts.action.*;
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;
/**
* @struts.action path="/hello" name="helloForm" input="/hello.jsp" scope="request" validate="true"
* @struts.action-forward name="failed" path="/hello.jsp"
* @struts.action-forward name="sayHello" path="/sayHello.jsp"
*/
public class HelloAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ActionMessages errors=new ActionMessages();
HelloForm helloForm = (HelloForm) form;
String userName=helloForm.getUserName();
String badUserName="monster";
if( userName.equals(badUserName) ){
errors.add("username",new ActionMessage("hello.dont.talk.to.monster",badUserName));
saveErrors(request,errors);
return(new ActionForward(mapping.getInput()));
}
else{
PersonBean pb=new PersonBean();
pb.setUserName(userName);
pb.save();
request.setAttribute(Constants.PERSON_KEY,pb);
request.removeAttribute(mapping.getAttribute());//將FormBean 從reqeust中清除,不需要此信息
return(new ActionForward(mapping.findForward("sayHello")));
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -