/*
* $Id: RequestUtils.java 384422 2006-03-09 04:17:18Z niallp $
*
* Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.struts.util;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.ActionServletWrapper;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.action.DynaActionFormClass;
import org.apache.struts.config.ActionConfig;
import org.apache.struts.config.FormBeanConfig;
import org.apache.struts.config.ForwardConfig;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.taglib.TagUtils;
import org.apache.struts.upload.MultipartRequestHandler;
import org.apache.struts.upload.MultipartRequestWrapper;
/**
* <p>General purpose utility methods related to processing a servlet request
* in the Struts controller framework.</p>
*
* @version $Rev: 384422 $ $Date: 2006-03-09 04:17:18 +0000 (Thu, 09 Mar 2006) $
*/
public class RequestUtils {
// ------------------------------------------------------- Static Variables
/**
* <p>Commons Logging instance.</p>
*/
protected static Log log = LogFactory.getLog(RequestUtils.class);
// --------------------------------------------------------- Public Methods
/**
* <p>Create and return an absolute URL for the specified context-relative
* path, based on the server and context information in the specified
* request.</p>
*
* @param request The servlet request we are processing
* @param path The context-relative path (must start with '/')
*
* @return absolute URL based on context-relative path
*
* @exception MalformedURLException if we cannot create an absolute URL
*/
public static URL absoluteURL(HttpServletRequest request, String path)
throws MalformedURLException {
return (new URL(serverURL(request), request.getContextPath() + path));
}
/**
* <p>Return the <code>Class</code> object for the specified fully qualified
* class name, from this web application's class loader.</p>
*
* @param className Fully qualified class name to be loaded
* @return Class object
*
* @exception ClassNotFoundException if the class cannot be found
*/
public static Class applicationClass(String className) throws ClassNotFoundException {
// Look up the class loader to be used
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = RequestUtils.class.getClassLoader();
}
// Attempt to load the specified class
return (classLoader.loadClass(className));
}
/**
* <p>Return a new instance of the specified fully qualified class name,
* after loading the class from this web application's class loader.
* The specified class <strong>MUST</strong> have a public zero-arguments
* constructor.</p>
*
* @param className Fully qualified class name to use
*
* @return new instance of class
* @exception ClassNotFoundException if the class cannot be found
* @exception IllegalAccessException if the class or its constructor
* is not accessible
* @exception InstantiationException if this class represents an
* abstract class, an interface, an array class, a primitive type,
* or void
* @exception InstantiationException if this class has no
* zero-arguments constructor
*/
public static Object applicationInstance(String className)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
return (applicationClass(className).newInstance());
}
/**
* <p>Create (if necessary) and return an <code>ActionForm</code> instance appropriate
* for this request. If no <code>ActionForm</code> instance is required, return
* <code>null</code>.</p>
*
* @param request The servlet request we are processing
* @param mapping The action mapping for this request
* @param moduleConfig The configuration for this module
* @param servlet The action servlet
*
* @return ActionForm instance associated with this request
*/
public static ActionForm createActionForm(
HttpServletRequest request,
ActionMapping mapping,
ModuleConfig moduleConfig,
ActionServlet servlet) {
// Is there a form bean associated with this mapping?
String attribute = mapping.getAttribute();
if (attribute == null) {
return (null);
}
// Look up the form bean configuration information to use
String name = mapping.getName();
FormBeanConfig config = moduleConfig.findFormBeanConfig(name);
if (config == null) {
log.warn("No FormBeanConfig found under '" + name + "'");
return (null);
}
ActionForm instance = lookupActionForm(request, attribute, mapping.getScope());
// Can we recycle the existing form bean instance (if there is one)?
try {
if (instance != null && canReuseActionForm(instance, config)) {
return (instance);
}
} catch(ClassNotFoundException e) {
log.error(servlet.getInternal().getMessage("formBean", config.getType()), e);
return (null);
}
return createActionForm(config, servlet);
}
private static ActionForm lookupActionForm(HttpServletRequest request, String attribute, String scope)
{
// Look up any existing form bean instance
if (log.isDebugEnabled()) {
log.debug(
" Looking for ActionForm bean instance in scope '"
+ scope
+ "' under attribute key '"
+ attribute
+ "'");
}
ActionForm instance = null;
HttpSession session = null;
if ("request".equals(scope)) {
instance = (ActionForm) request.getAttribute(attribute);
} else {
session = request.getSession();
instance = (ActionForm) session.getAttribute(attribute);
}
return (instance);
}
/**
* <p>Determine whether <code>instance</code> of <code>ActionForm</code> is
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
struts1.2源码 (328个子文件)
ValidWhenParser.g 7KB
nested-logic.gif 30KB
nested-html.gif 30KB
tilesUML.gif 22KB
tilesUML.gif 16KB
htmlUML.gif 16KB
actionUML.gif 15KB
logicUML.gif 14KB
configUML.gif 13KB
beanUML.gif 13KB
nestedUML.gif 12KB
nested-bean.gif 9KB
actionsUML.gif 6KB
Stamp.gif 5KB
jakarta-feather-small.gif 2KB
image001.gif 1KB
package.html 31KB
package.html 22KB
package.html 19KB
package.html 19KB
package.html 16KB
package.html 14KB
package.html 853B
package.html 835B
package.html 824B
package.html 788B
package.html 696B
package.html 648B
package.html 630B
package.html 404B
package.html 254B
RequestUtils.java 64KB
TagUtils.java 44KB
ActionServlet.java 43KB
RequestProcessor.java 42KB
FieldChecks.java 39KB
JavascriptValidatorTag.java 30KB
BaseHandlerTag.java 29KB
InsertTag.java 27KB
ActionConfig.java 24KB
FormTag.java 23KB
ModuleConfigImpl.java 23KB
MultipartBoundaryInputStream.java 22KB
Action.java 22KB
DynaActionForm.java 21KB
CommonsMultipartRequestHandler.java 21KB
I18nFactorySet.java 20KB
ImgTag.java 20KB
ValidWhenLexer.java 18KB
MessageResources.java 18KB
ConfigHelper.java 17KB
ComponentDefinition.java 17KB
ActionDispatcher.java 17KB
Resources.java 16KB
ConfigRuleSet.java 16KB
WildcardHelper.java 15KB
DigestingPlugIn.java 15KB
TilesPlugin.java 15KB
PutTag.java 14KB
DispatchAction.java 14KB
MultipartIterator.java 14KB
OptionsTag.java 13KB
XmlParser.java 13KB
TagUtils.java 13KB
MultipartRequestWrapper.java 12KB
WriteTag.java 12KB
ActionMessages.java 12KB
IterateTag.java 12KB
TilesRequestProcessor.java 12KB
ValidWhenParser.java 12KB
DefinitionsUtil.java 12KB
LinkTag.java 12KB
ModuleConfig.java 11KB
OptionsCollectionTag.java 11KB
FormBeanConfig.java 11KB
FormPropertyConfig.java 11KB
DefinitionsFactoryConfig.java 11KB
ControllerConfig.java 10KB
ReloadableDefinitionsFactory.java 10KB
ActionRedirect.java 10KB
LookupDispatchAction.java 10KB
PropertyMessageResources.java 10KB
DynaActionFormClass.java 10KB
NestedPropertyHelper.java 10KB
BeanValidatorForm.java 10KB
DownloadAction.java 9KB
SelectTag.java 9KB
ActionForm.java 9KB
ErrorsTag.java 9KB
ModuleConfigVerifier.java 9KB
BufferedMultipartInputStream.java 9KB
DiskMultipartRequestHandler.java 9KB
MessagesTag.java 9KB
ModuleUtils.java 9KB
ServletContextWriter.java 9KB
RedirectTag.java 9KB
MappingDispatchAction.java 9KB
IncludeTag.java 9KB
OptionTag.java 9KB
ActionConfigMatcher.java 8KB
共 328 条
- 1
- 2
- 3
- 4
newgo333
- 粉丝: 2
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 南京邮电大学数学实验:熟练掌握 Matlab 软件的基本命令和操作
- 2017校招真题校园招聘真题算法题(37道)Python源码.zip
- 基于单片机protues仿真的多功能自动饮水机系统设计(仿真图、源代码、演示视频)
- 二叉树7-1-1.cpp
- android 9.0 原生模拟器 签名文件
- 技术面试最后反问面试官的话 校招面试非技术问题有哪些 非技术问题如何回答.png
- NB-IOT-BC26全网通模块Altium+ CADENCE +PADS三种格式(原理图SCH+PCB封装库)文件.zip
- 基于微信小程序开发的校园失物招领系统源码毕业设计(优质项目源码).zip
- 词向量是一种将自然语言中的单词转换为数值向量的技术,它能够捕捉词义和上下文信息
- nmap与masscan的简单使用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0