分享
 
 
 

strutsr源码解读

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

html:form

org.apache.struts.action.ActionServlet;

ActionServlet extends HttpServlet

doGet

doPost

process(request, response);

{

processor = getRequestProcessor(config);

processor.process(request, response);

}

RequestProcessor 没有继承任何的类,只是一个repquest的处理器,逻辑封装

方法

public void process(HttpServletRequest request,

HttpServletResponse response)

{

//封装request

request = processMultipart(request);

/*

详细:

protected HttpServletRequest processMultipart(HttpServletRequest request) {

if (!"POST".equalsIgnoreCase(request.getMethod())) {

return (request);

}

String contentType = request.getContentType();

if ((contentType != null) &&

contentType.startsWith("multipart/form-data")) {

return (new MultipartRequestWrapper(request));

} else {

return (request);

}

}

*/

// Identify the path component we will use to select a mapping

String path = processPath(request, response);

if (path == null) {

return;

}

//begin 可以忽略

if (log.isDebugEnabled()) {

log.debug("Processing a '" + request.getMethod() +

"' for path '" + path + "'");

}

// Select a Locale for the current user if requested

processLocale(request, response);

// Set the content type and no-caching headers if requested

processContent(request, response);

processNoCache(request, response);

// General purpose preprocessing hook

if (!processPreprocess(request, response)) {

return;

}

this.processCachedMessages(request, response);

//end 忽略

// Identify the mapping for this request

ActionMapping mapping = processMapping(request, response, path);

if (mapping == null) {

return;

}

/*详细

根据path找到mapping

*/

// Check for any role required to perform this action

if (!processRoles(request, response, mapping)) {

return;

}

//action form 的处理

// Process any ActionForm bean related to this request

ActionForm form = processActionForm(request, response, mapping);

/*

用mapping找actionform

protected ActionForm processActionForm(HttpServletRequest request,

HttpServletResponse response,

ActionMapping mapping) {

// Create (if necessary) a form bean to use

ActionForm instance = RequestUtils.createActionForm

(request, mapping, moduleConfig, servlet);

/*详细

ActionForm instance = lookupActionForm(request, attribute, mapping.getScope());

if (instance != null && canReuseActionForm(instance, config)) {

return (instance);

否则

return createActionForm(config, servlet);

*/

if (instance == null) {

return (null);

}

// Store the new instance in the appropriate scope

if (log.isDebugEnabled()) {

log.debug(" Storing ActionForm bean instance in scope '" +

mapping.getScope() + "' under attribute key '" +

mapping.getAttribute() + "'");

}

if ("request".equals(mapping.getScope())) {

request.setAttribute(mapping.getAttribute(), instance);

} else {

HttpSession session = request.getSession();

session.setAttribute(mapping.getAttribute(), instance);

}

return (instance);

}

*/

processPopulate(request, response, form, mapping);

/*

RequestUtils.populate(form, mapping.getPrefix(), mapping.getSuffix(),

request);

*/

if (!processValidate(request, response, form, mapping)) {

return;

}

/*

protected boolean processValidate(HttpServletRequest request,

HttpServletResponse response,

ActionForm form,

ActionMapping mapping)

throws IOException, ServletException {

if (form == null) {

return (true);

}

// Was this request cancelled?

if (request.getAttribute(Globals.CANCEL_KEY) != null) {

if (log.isDebugEnabled()) {

log.debug(" Cancelled transaction, skipping validation");

}

return (true);

}

// Has validation been turned off for this mapping?

if (!mapping.getValidate()) {

return (true);

}

// Call the form bean's validation method

if (log.isDebugEnabled()) {

log.debug(" Validating input form properties");

}

ActionMessages errors = form.validate(mapping, request);

if ((errors == null) || errors.isEmpty()) {

if (log.isTraceEnabled()) {

log.trace(" No errors detected, accepting input");

}

return (true);

}

// Special handling for multipart request

if (form.getMultipartRequestHandler() != null) {

if (log.isTraceEnabled()) {

log.trace(" Rolling back multipart request");

}

form.getMultipartRequestHandler().rollback();

}

// Was an input path (or forward) specified for this mapping?

String input = mapping.getInput();

if (input == null) {

if (log.isTraceEnabled()) {

log.trace(" Validation failed but no input form available");

}

response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,

getInternal().getMessage("noInput",

mapping.getPath()));

return (false);

}

// Save our error messages and return to the input form if possible

if (log.isDebugEnabled()) {

log.debug(" Validation failed, returning to '" + input + "'");

}

request.setAttribute(Globals.ERROR_KEY, errors);

if (moduleConfig.getControllerConfig().getInputForward()) {

ForwardConfig forward = mapping.findForward(input);

processForwardConfig( request, response, forward);

} else {

internalModuleRelativeForward(input, request, response);

}

return (false);

}

*/

// Process a forward or include specified by this mapping

if (!processForward(request, response, mapping)) {

return;

}

if (!processInclude(request, response, mapping)) {

return;

}

// Create or acquire the Action instance to process this request

Action action = processActionCreate(request, response, mapping);

if (action == null) {

return;

}

// Call the Action instance itself

ActionForward forward =

processActionPerform(request, response,

action, form, mapping);

/*

protected ActionForward

processActionPerform(HttpServletRequest request,

HttpServletResponse response,

Action action,

ActionForm form,

ActionMapping mapping)

throws IOException, ServletException {

try {

return (action.execute(mapping, form, request, response));

} catch (Exception e) {

return (processException(request, response,

e, form, mapping));

}

}

*/

// Process the returned ActionForward instance

processForwardConfig(request, response, forward);

protected void processForwardConfig(HttpServletRequest request,

HttpServletResponse response,

ForwardConfig forward)

throws IOException, ServletException {

if (forward == null) {

return;

}

if (log.isDebugEnabled()) {

log.debug("processForwardConfig(" + forward + ")");

}

String forwardPath = forward.getPath();

String uri = null;

// paths not starting with / should be passed through without any processing

// (ie. they're absolute)

if (forwardPath.startsWith("/")) {

uri = RequestUtils.forwardURL(request, forward, null); // get module relative uri

} else {

uri = forwardPath;

}

if (forward.getRedirect()) {

// only prepend context path for relative uri

if (uri.startsWith("/")) {

uri = request.getContextPath() + uri;

}

response.sendRedirect(response.encodeRedirectURL(uri));

} else {

doForward(uri, request, response);

}

}

}

protected void doForward(

String uri,

HttpServletRequest request,

HttpServletResponse response)

throws IOException, ServletException {

// Unwrap the multipart request, if there is one.

if (request instanceof MultipartRequestWrapper) {

request = ((MultipartRequestWrapper) request).getRequest();

}

RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);

if (rd == null) {

response.sendError(

HttpServletResponse.SC_INTERNAL_SERVER_ERROR,

getInternal().getMessage("requestDispatcher", uri));

return;

}

rd.forward(request, response);

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有