/*
* ====================================================================
*
* Copyright (c) 2002 Caravel Technologies. All rights reserved.
*
* For information about the company, visit <http://www.caraveltech.com>.
*
* ====================================================================
*/
package com.caraveltech.ex2;
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.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;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.DynaActionForm;
/**
* Implementation of <strong>Action</strong> that accepts input for
* the user profile.
*
* @author Wellie W. Chao
* @version $Revision: 1.1 $ $Date: 2002/05/26 16:25:26 $
*/
public final class ProfileAction 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.
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request (if any)
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*
* @exception Exception if business logic throws an exception
*/
public ActionForward execute(ActionMapping mapping,
ActionForm baseForm,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
DynaActionForm form = (DynaActionForm)baseForm;
String thisActionClass = "com.caraveltech.ex2.ProfileAction";
String actionClass = (String)form.get("actionClass");
HttpSession session = request.getSession();
if (!thisActionClass.equals(actionClass)) {
// Do not try to act on the form if the user just pulled it up.
// Set the hidden field so the next time around we will know to
// act on the form data.
form.set("actionClass", thisActionClass);
// display the form for input.
return (new ActionForward(mapping.getInput()));
}
// Validate the request parameters specified by the user
ActionErrors errors = new ActionErrors();
if ((form.get("firstName") == null) ||
(((String)form.get("firstName")).length() < 1)) {
ActionError error =
new ActionError("error.firstName.required");
errors.add("firstName", error);
}
if ((form.get("lastName") == null) ||
(((String)form.get("lastName")).length() < 1)) {
ActionError error =
new ActionError("error.lastName.required");
errors.add("lastName", error);
}
if ((form.get("favoriteColor") == null) ||
(((String)form.get("favoriteColor")).length() < 1)) {
ActionError error =
new ActionError("error.favoriteColor.required");
errors.add("favoriteColor", error);
} else if (!"blue".equals(form.get("favoriteColor"))) {
ActionError error =
new ActionError("error.favoriteColor.mustBeBlue");
errors.add("favoriteColor", error);
}
if ((form.get("birthdate") == null) ||
(((String)form.get("birthdate")).length() < 1)) {
ActionError error =
new ActionError("error.birthdate.required");
errors.add("birthdate", error);
} else if (!((String)form.get("birthdate")).matches("\\d+{1,2}/\\d{1,2}/\\d{2}")) {
ActionError error =
new ActionError("error.birthdate.invalid");
errors.add("birthdate", error);
}
// Report any errors we have discovered back to the original form
if (!errors.empty()) {
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
}
// Remove the obsolete form bean
if (mapping.getAttribute() != null) {
if ("request".equals(mapping.getScope()))
request.removeAttribute(mapping.getAttribute());
else
session.removeAttribute(mapping.getAttribute());
}
// Place form values in request scope for bean:write tags
request.setAttribute("firstName", form.get("firstName"));
request.setAttribute("lastName", form.get("lastName"));
request.setAttribute("favoriteColor", form.get("favoriteColor"));
request.setAttribute("birthdate", form.get("birthdate"));
// Forward control to the specified success URI
return (mapping.findForward("success"));
}
}
struts-tiles-examples
4星 · 超过85%的资源 需积分: 3 182 浏览量
2008-11-13
16:34:33
上传
评论
收藏 64KB ZIP 举报
clj1986
- 粉丝: 0
- 资源: 3
最新资源
- 基于SpringBoot+Vue3快速开发平台、自研工作流引擎源码设计.zip
- docker安装部署全流程
- 基于树莓派的人脸识别系统python源码+项目部署说明+超详细代码注释.zip
- Python和R爬取分析赶集网北京二手房数据.zip
- Python和R爬取分析赶集网北京二手房数据.zip
- Java知识体系最强总结(2021版).txt
- Python知识点Python知识点Python知识点Python知识点Python知识点PythonPython知识点.txt
- Java开发基于seetaface6的人脸识别(活体检测)的封装源码.zip
- JSP在线失物招领管理平台源码.zip
- JSP在线旅游美食展现管理系统源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈