aspose file tools*
The moose likes Servlets and the fly likes Problem with accessing servlet from browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with accessing servlet from browser" Watch "Problem with accessing servlet from browser" New topic
Author

Problem with accessing servlet from browser

Srinivas Vanjari
Greenhorn

Joined: Dec 27, 2011
Posts: 7
Good morning to one and all....
Actually i have a problem with this code, am getting

HTTP Status 404 - /demo1/form.html
type Status report
message /demo1/form.html
description The requested resource (/demo1/form.html) is not available.



every time i am getting this error message when i access this url.... http://localhost:8080/demo1/form.html
i deployed it in webapps folder as a demo1 with .class file of FormServlet...

Could anyone help me to solve this issue..

form.html
-----------
<html>
<head>
<title>FormServlet</title>
</head>
<body>
<form action="./Servlets/form" method=Get>
FirstName:
<input type=text size=20 value=firstName>
<br>
LastName:
<input type=text size=10 value=lastName>
<br>
<input type=submit>
</form>
</body>
</html>

FormServlet.java
-------------------
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FormServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String firstname=request.getParameter("firstName");
String lastname=request.getParameter("lastName");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>FormServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1> User first name is" + firstname +"<h1>");
out.println("<h1> User Last name is" + lastname +"<h1>");
out.println("</body>");
out.println("</html>");
}
}

web.xml
---------

<web-app>
<servlet>
<servlet-name>Form</servlet-name>
<servlet-class>FormServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Form</servlet-name>
<url-pattern>/Servlet/form</url-pattern>
</servlet-mapping>
</web-app>


Thanks &Regards
------------------
Srinu
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 563
    
    3

First, Please use Code Tags while posting to Forums..
Next, put the servlets in a package, don't use default package. From Java 1.4, classes in default package cannot be imported.
Is the application deployed successfully? please post the server logs too..
rajesh thallamapuram
Greenhorn

Joined: Mar 06, 2012
Posts: 10
I think you kept the Form1.html somewhere inside the folder. please check once. keep the html file inside project and try.
Srinivas Vanjari
Greenhorn

Joined: Dec 27, 2011
Posts: 7
Thanks for your reply...

I placed it in a package,still am getting the same error
Srinivas Vanjari
Greenhorn

Joined: Dec 27, 2011
Posts: 7
Prasad Krishnegowda wrote:First, Please use Code Tags while posting to Forums..
Next, put the servlets in a package, don't use default package. From Java 1.4, classes in default package cannot be imported.
Is the application deployed successfully? please post the server logs too..



Thanks for your reply...

I placed it in a package,still am getting the same error
rajesh thallamapuram
Greenhorn

Joined: Mar 06, 2012
Posts: 10
did you check weather the project is deployed successfully or not?
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 563
    
    3

Post the server logs, also don't tell, Show us what you did (moving servlet to a package)..
Please remember to use code tags when you post the code..

EDIT: Did you check, where you have placed form.html, as suggested by Rajesh earlier?
Post the directory structure too..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with accessing servlet from browser