Learning J2ee, got newbie question.

D

DaLoverhino

Hello. I picked up a Beginner's J2ee book. I'm going through the
examples, but one of the examples I am stuck on. I cannot get past the
error message:

404 - Resource Not found.

I am running Tomcat, I believe 5.5.8. Here's the directory structure
that I have:

webapp/Ch05/
login.html
Login.java
Login.class


Here's the login.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Login</title>
</head>

<body>
<h1>Login</h1>

Please enter your username and password.
<form action="/Ch05/Login" method="POST">
<p><input type="text" name="username" length="40">
<p><input type="password" name="password" length="40">
<p><input type="submit" value="Submit">
</form>
</body>
</html>



My browser complains that Login resource is unavailable. Here's
Login.java, which is compiled and in the same directory.

package web;

import java.servlet.http.*;
import java.io.*;

public class Login extends HttpServlet {
public void doPost( HttpServletRequest request, HttpServletResponse
response)
{
String username = request.getParameter( "username");
try {
response.setContentType( "text/html");
PrintWriter writer = response.getWriter();
writer.println( "<html><body>");
writer,println( "Thank you, " + username +
". You are now logged into the system.");
writer.println( "</body></html>");
writer.close();
} catch( Exception e) {
e.printStackTrace();
}
}
}



Anyways, does anyone know what I'm doing wrong here? (I just typed the
example pretty quickly, so there might be typos, but the above compiles
without complaint.) Thanks.
 
I

info

DaLoverhino said:
Hello. I picked up a Beginner's J2ee book. I'm going through the
examples, but one of the examples I am stuck on. I cannot get past the
error message:

404 - Resource Not found.

Hope I didn't miss a detail. Check that the servlet is mapped
correctly in the web.xml file in the WEB-INF directory. It might need
something like:

<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Ch05/Login</url-pattern>
</servlet-mapping>

HTH

-- Kyle
 
T

trippy

DaLoverhino took the hamburger, threw it on the grill, and I said "Oh
wow"...
Hello. I picked up a Beginner's J2ee book. I'm going through the
examples, but one of the examples I am stuck on. I cannot get past the
error message:

404 - Resource Not found.

I am running Tomcat, I believe 5.5.8. Here's the directory structure
that I have:

webapp/Ch05/
login.html
Login.java
Login.class


Here's the login.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Login</title>
</head>

<body>
<h1>Login</h1>

Please enter your username and password.
<form action="/Ch05/Login" method="POST">
<p><input type="text" name="username" length="40">
<p><input type="password" name="password" length="40">
<p><input type="submit" value="Submit">
</form>
</body>
</html>



My browser complains that Login resource is unavailable. Here's
Login.java, which is compiled and in the same directory.

package web;

import java.servlet.http.*; //wrong

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Login extends HttpServlet {
public void doPost( HttpServletRequest request, HttpServletResponse
response)
{
String username = request.getParameter( "username");
try {
response.setContentType( "text/html");
PrintWriter writer = response.getWriter();
writer.println( "<html><body>");
writer,println( "Thank you, " + username +
". You are now logged into the system.");
writer.println( "</body></html>");
writer.close();
} catch( Exception e) {
e.printStackTrace();
}
}
}



Anyways, does anyone know what I'm doing wrong here? (I just typed the
example pretty quickly, so there might be typos, but the above compiles
without complaint.) Thanks.

--
trippy
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM

NP: "I Am The Law" -- Anthrax

"Now, technology's getting better all the time and that's fine,
but most of the time all you need is a stick of gum, a pocketknife,
and a smile."

-- Robert Redford "Spy Game"
 
P

Paul Hamaker

Are you sure about the presence of Login.class where you suppose it to
be, because your source contains an error :
writer,println( "Thank you, " + us......
comma instead of dot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top