Authenticating the username, password by using filters in Java (contacting with database)

String sql=”select * from reg where username=””+user+”” and pass=””+pwd+”””; This is an extremely bad practice. This approach requires that both username and password being passed around plain vanilla through requests. Moreover, you’ve there a SQL injection attack hole. Make use of sessions, in JSP/Servlet there you have the HttpSession for. There is really also no … Read more

Tomcat 8 enable debug logging to list unneeded jars

Try debugging for everything by: Adding this to the end of your logging.properties file located in {CATALINA-HOME}/conf: #To see the most detailed level of logging for all classes, uncomment the following line: org.apache.catalina.level=FINEST Restart Tomcat Run the following from Terminal to get a list of jars that need to be skipped (courtesy of @joseph-lust on … Read more

Selected value for JSP drop down using JSTL

In HTML, the selected option is represented by the presence of the selected attribute on the <option> element like so: <option … selected>…</option> Or if you’re HTML/XHTML strict: <option … selected=”selected”>…</option> Thus, you just have to let JSP/EL print it conditionally. Provided that you’ve prepared the selected department as follows: request.setAttribute(“selectedDept”, selectedDept); then this should … Read more

The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

Get rid of any servletcontainer-specific libraries such as jsp-api.jar in your /WEB-INF/lib folder. This exception indicates that you’ve put servletcontainer-specific libraries of a container which supports only Servlet 2.4 / JSP 2.0 or older in there (the getJspApplicationContext() method was introduced in Servlet 2.5 / JSP 2.1). This is a major mistake. Those libraries don’t … Read more

How to show user-friendly error page in browser when runtime exception is thrown by servlet?

Just declare an <error-page> in web.xml wherein you can specify the page which should be displayed on a certain Throwable (or any of its subclasses) or a HTTP status code. E.g. <error-page> <exception-type>java.lang.Exception</exception-type> <location>/error.jsp</location> </error-page> which will display the error page on any subclass of the java.lang.Exception, but thus not java.lang.Throwable or java.lang.Error. This way … Read more

How does Java expression language resolve boolean attributes? (in JSF 1.2)

It’s authoritatively documented in both the JavaBeans Spec and EL Specification. To take the boolean property as an example, it’s described in chapter 8.3.2 of JavaBeans spec: 8.3.2 Boolean properties In addition, for boolean properties, we allow a getter method to match the pattern: public boolean is<PropertyName>(); This “is<PropertyName>” method may be provided instead of … Read more

File upload with ServletFileUpload’s parseRequest? [duplicate]

As I said in a comment to the same question, you posted earlier, this is most likely because you have parsed the request already before. The files are part of the request body and you can parse it only one time. Update: I usually do use commons-upload in that way: if (ServletFileUpload.isMultipartContent(request)) { ServletFileUpload fileUpload … Read more

Java Front Controller [duplicate]

To start, create a Servlet which listens on a certain url-pattern, e.g. /pages/*. Implement the service() method to lookup the action associated with the request method (GET, POST, etc) and pathinfo (the URL part after the servlet’s url-pattern). Basic example: protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { View view = new View(request, … Read more