• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Problem with accessing servlet from browser

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did you check weather the project is deployed successfully or not?
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Friends help you move. Good friends help you move bodies. This tiny ad will help:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic