aspose file tools*
The moose likes Beginning Java and the fly likes Accessing servlet  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Accessing servlet

Srinivas Vanjari
Greenhorn

Joined: Dec 27, 2011
Posts: 7
Good morning 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.

this error message every time when i am accessing 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>
Jim Pouwels
Ranch Hand

Joined: Feb 22, 2012
Posts: 61
Where did you deploy the servlet to? A servlet container like Tomcat? Or an AS like JBoss? And if so, which configuration are you using?

F.e. what is the content of your web.xml
Srinivas Vanjari
Greenhorn

Joined: Dec 27, 2011
Posts: 7
Jim Pouwels wrote:Where did you deploy the servlet to? A servlet container like Tomcat? Or an AS like JBoss? And if so, which configuration are you using?

F.e. what is the content of your web.xml


In Tomcat only under webapps---- like demo1+
|
+form.html
|
+WEB-INF +
|
+classes+
| |+FormServlet.java
|
+lib
|
+web.xml
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

Please UseOneThreadPerQuestion. Let's continue here.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing servlet