What is WEB-INF used for in a Java EE web application?

The Servlet 2.4 specification says this about WEB-INF (page 70): A special directory exists within the application hierarchy named WEB-INF. This directory contains all things related to the application that aren’t in the document root of the application. The WEB-INF node is not part of the public document tree of the application. No file contained … Read more

How to use a servlet filter in Java to change an incoming servlet request 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

Java / Jakarta EE web development, where do I start and what skills do I need? [closed]

(Updated Apr 2021) First of all, “Java EE” has since Sep 2019 been renamed to “Jakarta EE“, starting with version 8. Historically, there was also the term “J2EE” which covered versions 1.2 until 1.4. The “Java EE” covered versions 5 until 8. See also Java Platform, Enterprise Edition, History on Wikipedia. What exactly do I … Read more

Where to place and how to read configuration resource files in servlet based application?

It’s your choice. There are basically three ways in a Java web application archive (WAR): 1. Put it in classpath So that you can load it by ClassLoader#getResourceAsStream() with a classpath-relative path: ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream input = classLoader.getResourceAsStream(“foo.properties”); // … Properties properties = new Properties(); properties.load(input); Here foo.properties is supposed to be placed … Read more

HttpServletRequest to complete URL

The HttpServletRequest has the following methods: getRequestURL() – returns the part of the full URL before query string separator character ? getQueryString() – returns the part of the full URL after query string separator character ? So, to get the full URL, just do: public static String getFullURL(HttpServletRequest request) { StringBuilder requestURL = new StringBuilder(request.getRequestURL().toString()); … Read more

Difference between getAttribute() and getParameter()

getParameter() returns http request parameters. Those passed from the client to the server. For example http://example.com/servlet?parameter=1. Can only return String getAttribute() is for server-side usage only – you fill the request with attributes that you can use within the same request. For example – you set an attribute in a servlet, and read it from … Read more

How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?

Ensure you’ve the right Eclipse and Server version Ensure that you’re using at least Eclipse IDE for Enterprise Java developers (with the Enterprise). It contains development tools to create dynamic web projects and easily integrate servletcontainers (those tools are part of Web Tools Platform, WTP). In case you already had Eclipse IDE for Java (without … Read more

How should I use servlets and Ajax?

Indeed, the keyword is “Ajax”: Asynchronous JavaScript and XML. However, last years it’s more than often Asynchronous JavaScript and JSON. Basically, you let JavaScript execute an asynchronous HTTP request and update the HTML DOM tree based on the response data. Since it’s pretty tedious work to make it to work across all browsers (especially Internet … Read more

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