📄 helloaction.java
字号:
/*
* 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")));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -