How can I get the HTTP status code out of a ServletResponse in a ServletFilter?

First, you need to save the status code in an accessible place. The best to wrap the response with your implementation and keep it there: public class StatusExposingServletResponse extends HttpServletResponseWrapper { private int httpStatus; public StatusExposingServletResponse(HttpServletResponse response) { super(response); } @Override public void sendError(int sc) throws IOException { httpStatus = sc; super.sendError(sc); } @Override public … Read more

Retrieving JSON Object Literal from HttpServletRequest

are you looking for this ? @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { StringBuilder sb = new StringBuilder(); BufferedReader reader = request.getReader(); try { String line; while ((line = reader.readLine()) != null) { sb.append(line).append(‘\n’); } } finally { reader.close(); } System.out.println(sb.toString()); }

Session TimeOut in web.xml

To set a session-timeout that never expires is not desirable because you would be reliable on the user to push the logout-button every time he’s finished to prevent your server of too much load (depending on the amount of users and the hardware). Additionaly there are some security issues you might run into you would … Read more

What does servletcontext.getRealPath(“/”) mean and when should I use it

Introduction The ServletContext#getRealPath() is intented to convert a web content path (the path in the expanded WAR folder structure on the server’s disk file system) to an absolute disk file system path. The “https://stackoverflow.com/” represents the web content root. I.e. it represents the web folder as in the below project structure: YourWebProject |– src | … Read more

HttpServletResponse sendRedirect permanent

You need to set the response status and the Location header manually. response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); response.setHeader(“Location”, “http://somewhere/”); Setting the status before sendRedirect() won’t work as sendRedirect() would overridde it to SC_FOUND afterwards.

javac command line compile error: package javax.servlet does not exist

You need to add the path to Tomcat’s /lib/servlet-api.jar file to the compile time classpath. javac -cp .;/path/to/Tomcat/lib/servlet-api.jar com/example/MyServletClass.java The classpath is where Java needs to look for imported dependencies. It will otherwise default to the current folder which is included as . in the above example. The ; is the path separator for Windows; … Read more

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