package hello;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.MessageResources;
public final class HelloAction extends Action {
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it).
* Return an <code>ActionForward</code> instance describing where and how
* control should be forwarded, or <code>null</code> if the response has
* already been completed.
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// These "messages" come from the ApplicationResources.properties file
MessageResources messages = getResources(request);
/*
* Validate the request parameters specified by the user
* Note: Basic field validation done in HelloForm.java
* Business logic validation done in HelloAction.java
*/
ActionMessages errors = new ActionMessages();
String userName = (String)((HelloForm) form).getUserName();
String badUserName = "Monster";
if (userName.equalsIgnoreCase(badUserName)) {
errors.add("username", new ActionMessage("hello.dont.talk.to.monster", badUserName ));
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
}
/*
* Having received and validated the data submitted
* from the View, we now update the model
*/
PersonBean pb = new PersonBean();
pb.setUserName(userName);
pb.saveToPersistentStore();
/*
* If there was a choice of View components that depended on the model
* (or some other) status, we'd make the decision here as to which
* to display. In this case, there is only one View component.
*
* We pass data to the View components by setting them as attributes
* in the page, request, session or servlet context. In this case, the
* most appropriate scoping is the "request" context since the data
* will not be neaded after the View is generated.
*
* Constants.PERSON_KEY provides a key accessible by both the
* Controller component (i.e. this class) and the View component
* (i.e. the jsp file we forward to).
*/
request.setAttribute( Constants.PERSON_KEY, pb);
// Remove the Form Bean - don't need to carry values forward
request.removeAttribute(mapping.getAttribute());
// Forward control to the specified success URI
return (mapping.findForward("SayHello"));
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
孙卫琴:精通struts helloapp源码 第一到四章
共194个文件
jar:50个
tld:31个
class:22个
3星 · 超过75%的资源 需积分: 3 20 下载量 96 浏览量
2008-11-22
11:54:10
上传
评论
收藏 11.52MB RAR 举报
温馨提示
孙卫琴:精通struts基于MVC的java web设计与开发,helloapp源码 第一到四章
资源推荐
资源详情
资源评论
收起资源包目录
孙卫琴:精通struts helloapp源码 第一到四章 (194个子文件)
encode.bat 93B
HelloAction.class 3KB
HelloAction.class 2KB
HelloAction.class 2KB
HelloAction.class 2KB
HelloAction.class 2KB
LocaleServlet.class 2KB
HelloForm.class 1KB
HelloForm.class 1KB
HelloForm.class 1KB
HelloForm.class 1KB
HelloForm.class 1KB
SetCharacterEncodingFilter.class 1KB
PersonBean.class 619B
PersonBean.class 619B
PersonBean.class 619B
PersonBean.class 619B
PersonBean.class 619B
Constants.class 346B
Constants.class 346B
Constants.class 346B
Constants.class 346B
Constants.class 346B
stylesheet.css 1KB
struts-power.gif 2KB
struts-power.gif 2KB
struts-power.gif 2KB
struts-power.gif 2KB
struts-power.gif 2KB
struts-power.gif 2KB
struts-power-ch.gif 2KB
inherit.gif 57B
HelloForm.html 11KB
PersonBean.html 10KB
HelloAction.html 10KB
index-all.html 9KB
Constants.html 9KB
help-doc.html 8KB
serialized-form.html 5KB
package-summary.html 5KB
constant-values.html 5KB
package-tree.html 5KB
overview-tree.html 5KB
deprecated-list.html 4KB
package-frame.html 1KB
allclasses-frame.html 969B
allclasses-noframe.html 889B
index.html 812B
packages.html 698B
commons-collections.jar 841KB
commons-collections.jar 841KB
commons-collections.jar 841KB
commons-collections.jar 841KB
commons-collections.jar 841KB
commons-collections.jar 841KB
struts.jar 506KB
struts.jar 506KB
struts.jar 506KB
struts.jar 506KB
struts.jar 506KB
struts.jar 506KB
log4j-1.2.8.jar 344KB
commons-digester.jar 178KB
commons-digester.jar 178KB
commons-digester.jar 178KB
commons-digester.jar 178KB
commons-digester.jar 178KB
commons-digester.jar 178KB
commons-beanutils.jar 148KB
commons-beanutils.jar 148KB
commons-beanutils.jar 148KB
commons-beanutils.jar 148KB
commons-beanutils.jar 148KB
commons-beanutils.jar 148KB
commons-validator.jar 79KB
commons-validator.jar 79KB
commons-validator.jar 79KB
commons-validator.jar 79KB
commons-validator.jar 79KB
commons-validator.jar 79KB
jakarta-oro.jar 64KB
jakarta-oro.jar 64KB
jakarta-oro.jar 64KB
jakarta-oro.jar 64KB
jakarta-oro.jar 64KB
jakarta-oro.jar 64KB
commons-logging.jar 39KB
commons-logging.jar 39KB
commons-logging.jar 39KB
commons-logging.jar 39KB
commons-logging.jar 39KB
commons-logging.jar 39KB
commons-fileupload.jar 22KB
commons-fileupload.jar 22KB
commons-fileupload.jar 22KB
commons-fileupload.jar 22KB
commons-fileupload.jar 22KB
commons-fileupload.jar 22KB
taglibs-log.jar 6KB
HelloAction.java 3KB
共 194 条
- 1
- 2
资源评论
- 急行在ios的路上2012-06-16入门,对新手还是有点用的
thiiikkk
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功