Sorry, but why go the hard way when you can achieve the same with a simple interceptor? You can return a global result from a interceptor (f.ex. return "errorPage") which is lot simpler than getting tangled with the RequestDispatcher stuff.
On 8/10/07, Toni Lyytikäinen <[EMAIL PROTECTED]> wrote: > > Sorry, but why go the hard way when you can achieve the same with a simple > interceptor? You can return a global result from a filter (f.ex. return > "errorPage") which is lot simpler than getting tangled with the > RequestDispatcher stuff. > > On 8/10/07, Eugen Stoianovici <[EMAIL PROTECTED]> wrote: > > > > i'm trying to use a custom filter to implement authorization and i can't > > get the damned thing to work (i'm an absolute beginner, be warned). > > i'm using struts2.0.8 with tomcat 5.5 > > > > my doFilter method looks like this > > public class AuthorizationFilter implements Filter { > > public void doFilter(ServletRequest request, ServletResponse response, > > FilterChain chain) throws IOException, ServletException { > > > > HttpServletRequest req = (HttpServletRequest) request; > > HttpServletResponse res = (HttpServletResponse) response; > > > > HttpSession session = req.getSession(); > > Employee employee = (Employee) session.getAttribute("user"); > > boolean hasRole = false; > > if(employee!=null){ > > for (int i = 0; i < roleNames.length; i++) { > > if (employee.hasRole(roleNames[i])) { > > hasRole = true; > > break; > > } > > } > > } > > if (hasRole) { > > chain.doFilter(request, response); > > } else { > > req.getRequestDispatcher(onErrorUrl).forward(req, res); > > } > > } > > } > > > > the browser reports: (line 47 is > > req.getRequestDispatcher(onErrorUrl).forward(req, res); ) > > > > *type* Exception report > > > > *message* > > > > *description* _The server encountered an internal error () that > > prevented it from fulfilling this request._ > > > > *exception* > > > > org.apache.jasper.JasperException > > org.apache.jasper.servlet.JspServletWrapper.handleJspException( > > JspServletWrapper.java:476) > > > > org.apache.jasper.servlet.JspServletWrapper.service ( > > JspServletWrapper.java:389) > > > > org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java > > :315) > > > > org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) > > javax.servlet.http.HttpServlet.service (HttpServlet.java:803) > > security.AuthorizationFilter.doFilter(AuthorizationFilter.java:47) > > > > *root cause* > > > > java.lang.NullPointerException > > org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java :58) > > org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack( > > StrutsBodyTagSupport.java:52) > > > > org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag( > > ComponentTagSupport.java:49) > > > > org.apache.jsp.index_jsp._jspx_meth_s_005furl_005f0(index_jsp.java:102) > > org.apache.jsp.index_jsp._jspService(index_jsp.java:62) > > org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) > > javax.servlet.http.HttpServlet.service(HttpServlet.java:803) > > org.apache.jasper.servlet.JspServletWrapper.service( > > JspServletWrapper.java:328) > > > > org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java > > :315) > > > > org.apache.jasper.servlet.JspServlet.service (JspServlet.java:265) > > javax.servlet.http.HttpServlet.service(HttpServlet.java:803) > > security.AuthorizationFilter.doFilter(AuthorizationFilter.java:47) > > > > * > > *__ > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > >