I have tomcat 7.0.14, jdk1.6 and Eclipse Indigo for Java EE web app developers.
I am new to JSP, so tried Eclipse as I thought it made coding easier. I closely followed this video tutorial.
I created 2 files under my project prison- login.java, home.html and modified web.xml too.
When I click the submit button in the login(this is 1st page) page, it shows only this error:
File not found
Firefox can't find the file at /D:/eclipse/Workspace/Prisonhome/WebContent/WEB-INF/Log?user=sa&pass=sa&action=That's+me.
I dont know if it isn’t sufficient to save project in workspace.
There were several discrepancies between file locations given in video and my Eclipse files. Eg.: web.xml in my Eclipse was located in servers->apache-tomcat directory, instead of web content->WEB_INF->lib->web.xml. is it important?
my code:
index.html
<html>
<head>
<title> Welcome :) </title>
</head>
<body>
<form action="Log" method="get">
<B>
<br><br><br><br><br><br><br><br><br><br><br><br>
Username: <input type=text name="user"><br><br>
Password: <input type=text name="pass"><br><br>
<input type=submit name=action value="That's me" style="background-color:666666; color:ffffff; border-color:ee0088">
</B></font>
</form>
</body>
</html>
Login.java:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uname=request.getParameter("user");
String passwd=request.getParameter("pass");
response.getWriter().println("<html><head>This is the response!</head>");
response.getWriter().println("<body>Response!!</body></html>");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
web.xml:
<servlet>
<servlet-name>Log</servlet-name>
<servlet-class>org.prisonhome.packs.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Log</servlet-name>
<url-pattern>/Log/*</url-pattern>
</servlet-mapping>
You need to open the page by a real web URL, not by a local disk file system path. If Tomcat is running at localhost on port 8080 and the webapp context name is
Prisonhomethen you need to invoke it byAs to the tutorials, I’d recommend to read the Coreservlets.com tutorials. You can find a list of links at bottom of our Servlets wiki page.
Unrelated to the concrete problem, using GET to login is not really safe as everyone can see the password in the URL. The HTML
<font>tag is deprecated since 1998, use CSS instead. Using a plethora of<br>and tags is also unnecessary, use CSS positions/margins/paddings instead.