Can I serve JSPs from inside a JAR in lib, or is there a workaround?

Servlet 3.0 which Tomcat 7 supports includes the ability to package jsps into a jar. You need to: place your jsps in META-INF/resources directory of your jar optionally include a web-fragment.xml in the META-INF directory of your jar place the jar in WEB-INF/lib directory of your war You should then be able to reference your … Read more

Accessing post variables using Java Servlets

Here’s a simple example. I didn’t get fancy with the html or the servlet, but you should get the idea. I hope this helps you out. <html> <body> <form method=”post” action=”/myServlet”> <input type=”text” name=”username” /> <input type=”password” name=”password” /> <input type=”submit” /> </form> </body> </html> Now for the Servlet import java.io.*; import javax.servlet.*; import javax.servlet.http.*; … Read more

how to send through ServletOutputStream characters in UTF-8 encoding

I think you want to use getWriter() instead. That will accept a string and encode it, whereas the output stream is for handling binary data. From the doc: Returns a PrintWriter object that can send character text to the client. The character encoding used is the one specified in the charset= property of the setContentType(java.lang.String) … Read more

SessionTimeout: web.xml vs session.maxInactiveInterval()

Now, i’m being told that this will terminate the session (or is it all sessions?) in the 15th minute of use, regardless their activity. This is wrong. It will just kill the session when the associated client (webbrowser) has not accessed the website for more than 15 minutes. The activity certainly counts, exactly as you … Read more

Convenient way to parse incoming multipart/form-data parameters in a Servlet [duplicate]

multipart/form-data encoded requests are indeed not by default supported by the Servlet API prior to version 3.0. The Servlet API parses the parameters by default using application/x-www-form-urlencoded encoding. When using a different encoding, the request.getParameter() calls will all return null. When you’re already on Servlet 3.0 (Glassfish 3, Tomcat 7, etc), then you can use … Read more

Get ServletContext in JAX-RS resource

Furthermore, @Resource annotation might not work. Try this @javax.ws.rs.core.Context ServletContext context; The injection doesn’t happen until you hit the service method public class MyService { @Context ServletContext context; public MyService() { print(“Constructor ” + context); // null here } @GET @Path(“/thing”) { print(“in wizard service ” + context); // available here

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