2

After searching Google for more than 3 hours, I'm giving up on this.

I have this web.xml:

<context-param> <param-name>contextClass</param-name> <param-value> org.springframework.web.context.support.AnnotationConfigWebApplicationContext </param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>ar.com.dera.simor.config</param-value> </context-param> <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <trim-directive-whitespaces>true</trim-directive-whitespaces> </jsp-property-group> </jsp-config> <error-page> <error-code>404</error-code> <location>/not_found</location> </error-page> 

OK, I did it work just with the servlet, and Spring Security. But also, I want to configure (in Java) the jsp-config and the error-page.

How can I do this? This is my WebInitializer class:

@Configuration public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebConfig.class); rootContext.scan("ar.com.dera.simor.config"); ServletRegistration.Dynamic appServlet = servletContext.addServlet( "appServlet", new DispatcherServlet(rootContext)); appServlet.setLoadOnStartup(1); appServlet.addMapping("/"); servletContext.addListener(new ContextLoaderListener(rootContext)); servletContext.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain")) .addMappingForUrlPatterns(null, false, "/*"); } @Override protected Class<?>[] getRootConfigClasses() { return new Class[] { SecurityConfig.class }; } @Override protected Class<?>[] getServletConfigClasses() { return new Class<?>[] { WebConfig.class }; } @Override protected String[] getServletMappings() { return new String[] { "/" }; } @Override protected Filter[] getServletFilters() { CharacterEncodingFilter utf8Filter = new CharacterEncodingFilter(); utf8Filter.setEncoding("UTF-8"); utf8Filter.setForceEncoding(true); return new Filter[] { utf8Filter }; } } 

1 Answer 1

3

Basically, you can't. ServletContext does not provide any methods to configure errors pages and JSPs from scratch. It does, however, provide a getJspConfigDescriptor method to get the <jsp-config> configuration (readonly).

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, so then, I have to keep web.xml.
@gaspo53 yeah, you can just use both.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.