站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Struts 专题Struts处理用户表单请求的核心源代码:

Struts处理用户表单请求的核心源代码:

摘要: Struts处理用户表单请求的核心源代码: Struts处理用户表单请求的核心源代码 Struts处理用户表单请求的核心源代码: ====================== ActionSer...
Struts处理用户表单请求的核心源代码:



↑返回目录
前一篇: Struts标记库
后一篇: Struts初步知识

Struts处理用户表单请求的核心源代码
Struts处理用户表单请求的核心源代码:





====================== ActionServlet ================================


/**



     * Process an HTTP "GET" request.



     *



     * @param request The servlet request we are processing



     * @param response The servlet response we are creating



     *



     * @exception IOException if an input/output error occurs



     * @exception ServletException if a servlet exception occurs



     */



    public void doGet(HttpServletRequest request,



              HttpServletResponse response)



        throws IOException, ServletException {







        process(request, response);







    }











    /**



     * Process an HTTP "POST" request.



     *



     * @param request The servlet request we are processing



     * @param response The servlet response we are creating



     *



     * @exception IOException if an input/output error occurs



     * @exception ServletException if a servlet exception occurs



     */



    public void doPost(HttpServletRequest request,



               HttpServletResponse response)



        throws IOException, ServletException {







        process(request, response);







    }

















    /**



     * Perform the standard request processing for this request, and create



     * the corresponding response.



     *



     * @param request The servlet request we are processing



     * @param response The servlet response we are creating



     *



     * @exception IOException if an input/output error occurs



     * @exception ServletException if a servlet exception is thrown



     */



    protected void process(HttpServletRequest request,



                           HttpServletResponse response)



        throws IOException, ServletException {







        RequestUtils.selectModule(request, getServletContext());



        getRequestProcessor(getModuleConfig(request)).process



            (request, response);







    }















__________________________________________________________________________


/**



     * Look up and return the {@link RequestProcessor} responsible for the



     * specified module, creating a new one if necessary.



     *



     * @param config The module configuration for which to



     *  acquire and return a RequestProcessor.



     *



     * @exception ServletException if we cannot instantiate a RequestProcessor



     *  instance



     * @since Struts 1.1



     */



    protected synchronized RequestProcessor getRequestProcessor(ModuleConfig config)



        throws ServletException {    



            



        String key = Globals.REQUEST_PROCESSOR_KEY + config.getPrefix();



        RequestProcessor processor = (RequestProcessor)



            getServletContext().getAttribute(key);



            



        if (processor == null) {



            try {



                processor =



                    (RequestProcessor) RequestUtils.applicationInstance(



                        config.getControllerConfig().getProcessorClass());



                        



            } catch (Exception e) {



                throw new UnavailableException(



                    "Cannot initialize RequestProcessor of class "



                        + config.getControllerConfig().getProcessorClass()



                        + ": "



                        + e);



            }







            processor.init(this, config);



            getServletContext().setAttribute(key, processor);







        }



        return (processor);







    }



















======================= RequestProcessor ===========================


-------------------------------- RequestProcessor ------------------------------------------------------


/**



     * <p>Process an <code>HttpServletRequest</code> and create the



     * corresponding <code>HttpServletResponse</code>.</p>



     *



     * @param request The servlet request we are processing



     * @param response The servlet response we are creating



     *



     * @exception IOException if an input/output error occurs



     * @exception ServletException if a processing exception occurs



     */



    public void process(HttpServletRequest request,



                        HttpServletResponse response)



        throws IOException, ServletException {







        // Wrap multipart requests with a special wrapper



        request = processMultipart(request);







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



        String path = processPath(request, response);



        if (path == null) {



            return;



        }



        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;



        }







        // Identify the mapping for this request



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



        if (mapping == null) {



            return;



        }







        // Check for any role required to perform this action



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



            return;



        }







        // Process any ActionForm bean related to this request



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



        processPopulate(request, response, form, mapping);



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



            return;



        }







        // 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);







        // Process the returned ActionForward instance



        processForwardConfig(request, response, forward);







    }











------------------------------------- RequestProcessor. --------------------------------------------------


/**



     * Ask the specified <code>Action</code> instance to handle this



     * request.  Return the <code>ActionForward</code> instance (if any)



     * returned by the called <code>Action</code> for further processing.



     *



     * @param request The servlet request we are processing



     * @param response The servlet response we are creating



     * @param action The Action instance to be used



     * @param form The ActionForm instance to pass to this Action



     * @param mapping The ActionMapping instance to pass to this Action



     *



     * @exception IOException if an input/output error occurs



     * @exception ServletException if a servlet exception occurs



     */



    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));



        }







    }