Struts RequestProcessor()问题

03-11-04 chaozai
如下边代码,RequestProcessor的process()方法中调用processContent(request,response)设置contentType,能否通过配置来解决中文问题,而不依赖于filter或其他方法?请赐教。

The process( ) method processes all requests 

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.isInfoEnabled(  )) {
      log.info("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
    processActionForward(request, response, forward);
}
<p>

banq
2003-11-07 17:45
感觉没有filter稳妥,而且struts结构经常变化,万一下个版本不用RequestProcessor?

liuyanjun_wx
2003-11-10 10:27
通过继承ActionServlet方法中调用process(request,response)设置contentType。这样可以不用跟改struts本身(注意修改web.xml文件)。

public class EncodingActionServlet extends ActionServlet {

public void process(HttpServletRequest req, HttpServletResponse res)

throws ServletException, IOException {

req.setCharacterEncoding("GB2312");

/*

System.out.println(req.getMethod() +req.getParameterNames() +"\n"+req.getParameter("address1"));

Enumeration e = req.getParameterNames();

while(e.hasMoreElements()){

System.out.println(e.nextElement());

}

*/

//res.setCharacterEncoding("iso8859-1");

super.process(req,res);

}

}

猜你喜欢