Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with accessing servlet from browser

 
Srinivas Vanjari
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 670
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply...

I placed it in a package,still am getting the same error
 
Srinivas Vanjari
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you check weather the project is deployed successfully or not?
 
Prasad Krishnegowda
Ranch Hand
Posts: 670
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic