ich hab zwar jetzt irgendwie (ob richtig weiss ich nicht) das java file kompiliert und die klasse sowie java file in das vorhergesehene file am tomcat abgespeichert, aber ich bekomme am tomcat dennoch eine fehlermeldung... brauch ich irgendeine bean oder so? (bin ein anfänger)
alles was ich gemacht habe ist das:
1. Tomcat Ordnerstruktur erstellen:
<TOMCAT_HOME>/webapps/onjava
=====> images (directory)
=====> WEB_INF
==========> classes
==========> lib
2. web.xml erstellen in <TOMCAT_HOME>/webapps/onjava/WEB_INF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
</web-app>
3. ServletContext hinzufügen in <TOMCAT_HOME>/conf/server.xml
<Context path="/onjava" docBase="onjava" debug="0" reloadable="true" />
4. login.jsp erstellen in <TOMCAT_HOME>/webapps/onjava/
<html>
<head>
<title>OnJava Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" onLoad="document.loginForm.username.focus()">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<form name="loginForm" method="post" action="servlet/com.onjava.login">
<tr>
<td width="401"><div align="right">User Name: </div></td>
<td width="399"><input type="text" name="username"></td>
</tr>
<tr>
<td width="401"><div align="right">Password: </div></td>
<td width="399"><input type="password" name="password"></td>
</tr>
<tr>
<td width="401"> </td>
<td width="399"><br><input type="Submit" name="Submit"></td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
5. Testen der JSP (Tomcat starten)
http://localhost:8080/onjava/login.jsp
6. welcome.jsp login.jsp erstellen in <TOMCAT_HOME>/webapps/onjava/
<html>
<head>
<title>OnJava Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td>
<img src="/onjava/images/monitor2.gif"></td>
<td>
<b>Welcome : <%= request.getAttribute("USER")
%></b>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
7. kompilieren von login.java
package com.onjava;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class login extends HttpServlet {
private String target = "/welcome.jsp";
private String getUser(String username, String password) {
// Just return a static name
// If this was reality, we would perform a SQL lookup
return "Bob";
}
public void init(ServletConfig config)
throws ServletException {
super.init(config);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// If it is a get request forward to doPost()
doPost(request, response);
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Get the username from the request
String username = request.getParameter("username");
// Get the password from the request
String password = request.getParameter("password");
String user = getUser(username, password);
// Add the fake user to the request
request.setAttribute("USER", user);
// Forward the request to the target named
ServletContext context = getServletContext();
RequestDispatcher dispatcher =
context.getRequestDispatcher(target);
dispatcher.forward(request, response);
}
public void destroy() {
}
}
8. login.java und login.class speichern in <TOMCAT_HOME>/webapps/onjava/WEB_INF/classes/com/onjava
9. Servlet Eintrag im web.xml hinzufügen (<TOMCAT_HOME>/webapps/onjava/WEB_INF)
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>com.onjava.login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
10. Invoker nicht kommentieren in <TOMCAT_HOME>/conf/web.xml
(2 Stellen)
11. Testen der login.jsp und welcome.jsp (Tomcat neu starten)
http://localhost:8080/onjava/login.jsp
Fehlermeldung 404
resource: onjava/servlet/login ist not available
ich hoffe du kannst mir helfen