Hi all,

I have created a simple servlet with one one JSP.

The files are,


    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Login Page</title>
    <link rel="stylesheet" type="text/css" href="css/style1.css" />

<div style="background: LightBlue  ">
    <h1 align="center">Sample Application</h1>

<FORM action="/myServlet" method="GET">
    What's your name?


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


package classes.servlet;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class myServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
        PrintWriter out = res.getWriter();
        String name = req.getParameter("name");
        out.println("<HEAD><TITLE>Hello, " + name + "</TITLE></HEAD>" );
        out.println("Hello, " + name);

When im trying to give name & press Submit, error is coming as,

HTTP Status 404 - /myServlet
type : Status report
message : /myServlet
description : The requested resource (/myServlet) is not available.
Apache Tomcat/5.5.17

Im using NetBeans, My folder Structure is,

C:\Documents and Settings\mani\test\web\index.jsp
C:\Documents and Settings\mani\test\web\WEB-INF\web.xml
C:\Documents and Settings\mani\test\src\java\classes\servlet\myServlet.java

Please help me in this regard.....

9 Years
Discussion Span
Last Post by stultuske

Thanks for your reply...
Im accessing the index page as "http://localhost:8084/test/index.jsp"
while redirecting to the servlet, the URL is displaying as "http://localhost:8084/myServlet?name=rani"

It is displaying without the project name, When i manually used to edit the URL, i mean, i have edit the URL by including the project name as "http://localhost:8084/test/myServlet?name=rani",
Then i got the perfect result. So, what may the problem? Please Explain. Where i have to change the code?

And then i wish to store in the database(MySQL).
So where i have to include DB Connection code? whether in java servlet or somewhere else?
Please explain this also...

I have tried myself the DB connection and storage, But i failed, got upset...

Please me and explain....
Awaiting for your reply with DB explaination...
For your note, i have reffered many books but i didnt get the proper knowledge... Help me please.....


> Please Explain. Where i have to change the code?

Try changing your markup; your HTML page doesn't understand your *servlet project* and hence you need to specify the extra "/test" before your servlet name.

> So where i have to include DB Connection code?

In your DAO classes.

> i have reffered many books but i didnt get the proper
> knowledge... Help me please.....

Refer the sticky thread at the top of this forum along with the JEE 5 documentation for some concrete examples.

Votes + Comments
Ah... So is it finally the return of the king ??? :P


thank uoi very much for your guidence...
Now its working....
i have tried to change my servlet name as /test/myServlet... Still it was not working... But i tried to give the full url in my form action.... Its now working....

Now i tried to connect DB(Insertion & Selection) by writing the code in servlet itself and DAO class..... Got the result... very happy.....

Now learning beans in progress.....
Thank you for your help....


Had the same problem
The action form acts just like a web browser that runs the page on the server so...
Pasting the full path of the page works fine.
Thanks everyone.

Edited by Ezzaral: Editing reason for editing. Not really a necessary comment.

Votes + Comments
I will select a less offensive username for you
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.