0

Following my previous post here, I've removed all my source files into a package called model , and now the project refuses to load while executing http://localhost:8080/MyFirstServlet.

I suspect the culprit is web.xml , here's the file :

web.xml:

<?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>MyFirstServlet</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
   <description></description>
   <display-name>LoginServlet</display-name>
   <servlet-name>LoginServlet</servlet-name>
   <servlet-class>model.LoginServlet</servlet-class>
 </servlet>


  <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>/model/LoginServlet</url-pattern>
  </servlet-mapping>
</web-app>

  [1]: https://stackoverflow.com/questions/11282231/jsp-page-wont-move-the-another-page-after-user-enters-the-input/11283006#11283006

this is index.jsp:

<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Insert title here</title>
</head>
<body>
<form action="model/LoginServlet" method="POST">
        First Name: <input type="text" name="firstName" size="20"><br>
        Last Name: <input type="text" name="lastName" size="20">
        <br><br>
        <input type="submit" value="Submit">
</form> 

</body>
</html>

This is the hierarchy of the project :

hierarchy

When I execute http://localhost:8080/MyFirstServlet and reach here :

enter image description here

I enter first and second into the text fields and then get this :

enter image description here

I've tried to fix it but nothing did , so I'd appreciate any advice , thanks :)

Community
  • 1
  • 1
JAN
  • 21,236
  • 66
  • 181
  • 318

4 Answers4

1
<servlet>
   <description></description>
   <display-name>LoginServlet</display-name>
   <servlet-name>LoginServlet</servlet-name>
   <servlet-class>model.LoginServlet</servlet-class>
 </servlet>

You missed the package for the servlet-class.

Udo Held
  • 12,314
  • 11
  • 67
  • 93
  • If that still doesn't work you should have a new different stacktrace. Otherwise your new web.xml isn't deployed properly and its still refering to the old one. – Udo Held Jul 03 '12 at 05:19
1

You form action should be

<form action="model/LoginServlet" />

and your Login servlet should define the package correctly.

package model;

Also your web.xml must declare this servlet class through fully qualified name

model.LoginServlet

Your servlet must extend HttpServlet.

If you make sure that all of the above are in place correctly and it still doesn't work. Then, You may need to check your build path settings in eclipse for this project.

0

The stacktrace clearly shows what the error is , the ClassNotFoundException means the servlet Container is not able to find the specified Class in the web.xml .

amitprot
  • 1
  • 2
  • I can see that , but how do I fix it ? – JAN Jul 01 '12 at 16:23
  • Please do cleanup of your Servlet , remove warnings / unnecessary referenced packages and then try to redeploy everything by stoping the tomcat and deploy and then start the server . Let me know if you still does not work . – amitprot Jul 01 '12 at 18:02
0

The first line of code in LoginServlet.java should be

package model;
rickz
  • 4,324
  • 2
  • 19
  • 30