I’m very new to Web programming and am trying to write a simple application to collect data from an input form and pass it to a servlet via HTTPServletRequest. I know each servlet needs to be mapped to a particular URL inside web.xml. My web.xml looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>InputFormTest</display-name>
<welcome-file-list>
<welcome-file>InputForm.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>InputFormTest</display-name>
<servlet-name>InputFormTest</servlet-name>
<servlet-class>com.jsp.core.InputFormTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InputFormTest</servlet-name>
<url-pattern>/InputFormTest</url-pattern>
</servlet-mapping>
</web-app>
InputForm.jsp shows correctly. I’ve added the InputFormTest servlet using Eclipse’s context menu, i.e. New -> Servlet, which has the following code:
package jsp.core;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class InputFormTest
*/
public class InputFormTest extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>InputFormTest</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>User inserted: " + request.getParameter("id") + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
I have two problems:
-
Firstly, after running the application within Eclipse, I’m getting the following error
HTTP Status 404 – /InputFormTest
type Status report
message /InputFormTest
description The requested resource is not available.
Apache Tomcat/6.0.36
-
Secondly, changing
<url-pattern>/InputFormTest</url-pattern>inweb.xmldoesn’t influence the above output, which is weird, because I’d assumemessage /InputFormTestshould reflect the setting withinweb.xml
Any hints appreciated.
OK, I finally figured it out. As one could guess, the answer is trivial: Eclipse internal browser caches pages.
This means, the page being shown in Eclipse internal browser after running the newly changed project using “Run as -> Run on server” is an old, cached page. It needs to be manually refreshed afterwards. Kind of weird behavior in case of a web-development project. Apart from that, everything works fine – case closed.