# Servlet Ausführungsfehler



## mavinatic (29. Okt 2010)

Hallo ihrs,

ich habe ein Problem und zwar habe ich ein Servlet angelegt und möchte das ausführen in meinem Deployment Descriptor(web.xml) habe ich es eingetragen und gemappt aber wenn ich es in einem Formular ausführen möchte, kommt immer ERROR 404

Ich versteh es nicht, aber hier die Quelltexte

WEB.XML
[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>ProductManager</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>admin.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>
		<servlet-name>ProductClassServlet</servlet-name>
		<servlet-class>servlets.ProductClassServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>ProductClassServlet</servlet-name>
		<url-pattern>/ProductClassServlet</url-pattern>
	</servlet-mapping>
</web-app>[/XML]

Mein Servlet:

```
package servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import de.framework.ProductManager.DataObject.ProductClass;

/**
 * Servlet implementation class productServlet
 */
public class ProductClassServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProductClassServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		System.out.println(config.getServletName());
		System.out.println("INIT!");
		/*
		 * Creating Database Connection with Hibernate
		 */
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		ProductClass prodClass = new ProductClass(request.getParameter("ProductClass_Name"));
		prodClass.setClassId("ID");
		
		//Insert with Hibernate to Database
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
```

Meine HTML Seite

```
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<!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=ISO-8859-1">
		<title>Create ProductClass</title>
	</head>
	<body>
		<h2>Create a Product Class</h2><p>
		<form name="CreateProductClass" action="/ProductClassServlet">
			<table name="tableForm">
				<tr>
					<td>ProductClass_Name</td>
					<td><input name="ProductClass_Name"></td>
				</tr>
			</table>
			<input type="submit" value="Create">
		</form>
	</body>
</html>
</body>
</html>
```


----------



## mvitz (29. Okt 2010)

Dein Link im Formular ist auch falsch.

/ProductClassServlet --> http://server:port/ProductClassServlet

was du allerdings brauchst ist: http://server:port/CONTEXT/ProductClassServlet

Fürs erste reicht es einfach deine Formular Action auf die richtige URL zu setzen.


----------



## mavinatic (30. Okt 2010)

Welchen KOntext benötige ich?


----------



## mvitz (30. Okt 2010)

Kommt darauf an, wie du das ganze deployst z.B.

Wenn du ein WAR in den Tomcat webapps Folder kopierst, dann ist der Kontext der Name des WAR Files. Eclipse nimmt standardmäßig den Namen des Projektes.

Alternativ geht auch noch


```
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<!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=ISO-8859-1">
		<title>Create ProductClass</title>
	</head>
	<body>
		<h2>Create a Product Class</h2><p>
		<form name="CreateProductClass" action="${pageContext.request.contextPath}/ProductClassServlet">
			<table name="tableForm">
				<tr>
					<td>ProductClass_Name</td>
					<td><input name="ProductClass_Name"></td>
				</tr>
			</table>
			<input type="submit" value="Create">
		</form>
	</body>
</html>
</body>
</html>
```


----------



## mavinatic (30. Okt 2010)

ah okay


----------

