How to retrieve raw post data from HttpServletRequest in java

The request body is available as byte stream by HttpServletRequest#getInputStream(): InputStream body = request.getInputStream(); // … Or as character stream by HttpServletRequest#getReader(): Reader body = request.getReader(); // … Note that you can read it only once. The client ain’t going to resend the same request multiple times. Calling getParameter() and so on will implicitly also … Read more

ServletConfig vs ServletContext

The ServletConfig parameters are specified for a particular servlet and are unknown to other servlets. It is used for intializing purposes. The ServletContext parameters are specified for an entire application outside of any particular servlet and are available to all the servlets within that application. It is application scoped and thus globally accessible across the … Read more

How to read and copy the HTTP servlet response output stream content for logging

You need to create a Filter wherein you wrap the ServletResponse argument with a custom HttpServletResponseWrapper implementation wherein you override the getOutputStream() and getWriter() to return a custom ServletOutputStream implementation wherein you copy the written byte(s) in the base abstract OutputStream#write(int b) method. Then, you pass the wrapped custom HttpServletResponseWrapper to the FilterChain#doFilter() call instead … Read more

How to access static resources when mapping a global front controller servlet on /*

Map the controller servlet on a more specific url-pattern like /pages/*, put the static content in a specific folder like /static and create a Filter listening on /* which transparently continues the chain for any static content and dispatches requests to the controller servlet for other content. In a nutshell: <filter> <filter-name>filter</filter-name> <filter-class>com.example.Filter</filter-class> </filter> <filter-mapping> … Read more

What does WEB-INF stand for in a Java EE web application? [closed]

As far as I know, “INF” stands for “Information”, as you said. It probably was named WEB-INF for similarity with the META-INF directory in JAR files. Sometimes the meaning of a directory changes so much over time that it no longer makes sense. For example, bin directories in Unix/Linux often contain non-binary “executable” files, such … Read more

How can I get client information such as OS and browser

Your best bet is User-Agent header. You can get it like this in JSP or Servlet, String userAgent = request.getHeader(“User-Agent”); The header looks like this, User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.13) Gecko/2009073021 Firefox/3.0.13 It provides detailed information on browser. However, it’s pretty much free format so it’s very hard to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)