How to use a Servlet Filter to change/rewrite an incoming URL?

Implement javax.servlet.Filter. In doFilter() method, cast the incoming ServletRequest to HttpServletRequest. Use HttpServletRequest#getRequestURI() to grab the path. Use straightforward java.lang.String methods like substring(), split(), concat() and so on to extract the part of interest and compose the new path. Use either ServletRequest#getRequestDispatcher() and then RequestDispatcher#forward() to forward the request/response to the new URL (server-side redirect, … Read more

IntelliJ and WAR….changed files are not automatically recognized by server

This cannot be done if you deploy a war with IntelliJ IDEA. However, it can be if you deploy an exploded war. In IDEA: open your Tomcat Run/Debug configuration (Run > Edit Configurations) Go to the “Deployment” tab In the “Deploy at Server Startup” section, remove (if present) the artifact my-webapp-name:war Click the add icon, … Read more

How exactly are the root context and the dispatcher servlet context into a Spring MVC web application?

Root Context The root-context in a Spring application is the ApplicationContext that is loaded by the ContextLoaderListener. This context should have globally available resources like services, repositories, infrastructure beans (DataSource, EntityManagerFactorys etc.) etc. The ContextLoaderListener registers this context in the ServletContext under the name org.springframework.web.context.WebApplicationContext.ROOT. If you load an ApplicationContext yourself and register it with … Read more

Why do cookie values with whitespace arrive at the client side with quotes?

When you set a cookie value with one of the following values as mentioned in Cookie#setValue(), With Version 0 cookies, values should not contain white space, brackets, parentheses, equals signs, commas, double quotes, slashes, question marks, at signs, colons, and semicolons. Empty values may not behave the same way on all browsers. then the average … Read more

JSESSIONID Cookie with Expiration Date in Tomcat

As of Servlet 3.0, this can simply be specified in the web.xml: <session-config> <session-timeout>720</session-timeout> <!– 720 minutes = 12 hours –> <cookie-config> <max-age>43200</max-age> <!– 43200 seconds = 12 hours –> </cookie-config> </session-config> Note that session-timeout is measured in minutes but max-age is measured in seconds.