I was hoping to avoid filters for a bunch of reasons (not going to get into them here).
Does anyone if the below technique of subclassing RequestProcessor is the "right" way to go in struts? Or can I do something in the action handler before RequestProcessor is called? Randy -----Original Message----- From: Kris Schneider [mailto:[EMAIL PROTECTED] Sent: Monday, November 15, 2004 9:57 AM To: Struts Users Mailing List Subject: Re: Request.setCharacterEncoding question If you've got a copy of Tomcat installed, look at: $CATALINA_HOME/webapps/servlets-examples/WEB-INF/classes/filters/SetChar acterEncodingFilter.java Quoting Randy Eckhoff <[EMAIL PROTECTED]>: > With the 2.3 servet API, there is a new method: > > request.setCharacterEncoding(String encoding) > > This lets you tell the server a request's character encoding. It is > critical that setCharacterEncoding is called BEFORE any > request.getParameter is called (or getReader). Otherwise, you are at > the mercy of the appserver for what you get back on the getParameter > call. For example, if setCharacterEncoding is not called, you could > get a null value back on getParameter("foo"). > > When you post directly to a jsp (MVC 1), the "entry point" for > servicing the page is ultimately the page itself. So JspCompilers have > request.setCharacterEncoding("whatever"); in the generated java code > as one of the first things that get done. > > But with Struts, the entry point is not the JSP but rather the action. > You eventually forward to the view but by that point, you've already > processed the request. > > So my question is this: For struts actions and forms and anything else > struts, is there 1 common place where we can override something to > call request.setCharacterEncoding(). Is > RequestProcessor.processPreprocess > the place to do it? I grepped the struts 1.2.4 source code and only > found a setCharacterEncoding on upload\MultipartRequestWrapper.java. > That method is a no-op. Ideally, we only want to override 1 method that > will handle the request's encoding for form validation and the action > handlers, etc. If processPreprocess is NOT the place to do this, > where/how should we do this? The ActionServlet instance perhaps that > calls RequestProcessor.process()? The action handler knows what encoding > to use so somehow, I would have to tell the request processor the > "encoding" unless I can override something in the ActionServlet before > process() gets called. > > I did *some* searching through the struts source code and in > RequestProcessor, the call to processPopulate does a getParameter: > if ((request.getParameter(Constants.CANCEL_PROPERTY) != null) || > (request.getParameter(Constants.CANCEL_PROPERTY_X) != > null)) { > > So calling setCharacterEncoding has to be done before > processPopulate(). > > Thanks! > > Randy -- Kris Schneider <mailto:[EMAIL PROTECTED]> D.O.Tech <http://www.dotech.com/> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]