How to implement @RequestMapping custom properties

I’ve created solution based on referenced spring-mvc-31-demo This solution can be used to map only single RequestCondition as of now. I’ve created two Issues to notify, this should be changed: https://github.com/rstoyanchev/spring-mvc-31-demo/issues/5 https://jira.springsource.org/browse/SPR-9350 This solution uses custom @RequestCondition feature of Spring 3.1.1.RELEASE platform USAGE Example 1: @Controller @SubdomainMapping(value = “subdomain”, tld = “.mydomain.com”) class MyController1 { … Read more

Spring v3 no declaration can be found for element ‘mvc:resources’

In your spring context xml mvc namespace url should match url in schemaLocation. Something like this: <?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:mvc=”http://www.springframework.org/schema/mvc” xsi:schemaLocation=” http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd”> This is a standard XML namespace declaration. The namespace url is sort of an unique id, which is then mapped to the actual schema location in xsi:schemaLocation.

Logging response body (HTML) from HttpServletResponse using Spring MVC HandlerInterceptorAdapter

This would be better done using a Servlet Filter rather than a Spring HandlerInterceptor, for the reason that a Filter is allowed to substitute the request and/or response objects, and you could use this mechanism to substitute the response with a wrapper which logs the response output. This would involve writing a subclass of HttpServletResponseWrapper, … Read more

Autowiring in servlet

I followed the solution in the following link, and it works fine: Access Spring beans from a servlet in JBoss public class MyServlet extends HttpServlet { @Autowired private MyService myService; public void init(ServletConfig config) { super.init(config); SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext()); } }

Using ServletOutputStream to write very large files in a Java servlet without memory issues

The average decent servletcontainer itself flushes the stream by default every ~2KB. You should really not have the need to explicitly call flush() on the OutputStream of the HttpServletResponse at intervals when sequentially streaming data from the one and same source. In for example Tomcat (and Websphere!) this is configureable as bufferSize attribute of the … Read more

Is there a static way to get the current HttpServletRequest in Spring

If you are using spring you can do the following: public static HttpServletRequest getCurrentHttpRequest(){ RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); if (requestAttributes instanceof ServletRequestAttributes) { HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest(); return request; } logger.debug(“Not called in the context of an HTTP request”); return null; }

Disable all default HTTP error response content in Tomcat

If you do not want tomcat to show an error page, then do not use sendError(…). Instead use setStatus(…). e.g. if you want to give a 405 response, then you do response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); response.getWriter().println(“The method ” + request.getMethod() + ” is not supported by this service.”); Also remember not to throw any Exceptions from your servlet. … Read more

Why do we use web.xml? [closed]

Generally speaking, this is the configuration file of web applications in java. It instructs the servlet container (tomcat for ex.) which classes to load, what parameters to set in the context, and how to intercept requests coming from browsers. There you specify: what servlets (and filters) you want to use and what URLs you want … Read more