• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet not being called from html

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i am using eclipse 3.2 tomcat project to call a servlet from a html page.(code follows), but it does not get the servlet.please help.

/*******HTML:********SERVLET is the name of my project/
<html>
<body>
<h3>Enter your user id and password</h3><p>
<form action = "/SERVLET/ray.servlet.RequestServlet" method = "POST">
UserId: <input type = "text" name= "userid"><br><br>
<input type = submit value ="show statement">
</form>
</body>
</html>

/****Servlet****/
package ray.servlet;

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 RequestServlet extends HttpServlet
{
private PrintWriter out;
private String name;

public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
out = res.getWriter();
out.println("<html><body>");
out.println("hello");
name = req.getParameter("userid");
out.println("Welcome "+name+"<br>");
}

}
/*******WEB.xml *********/
<?xml version = "1.0"?>
<web-app>
<servlet>
<servlet-name>REQ</servlet-name>
<servlet-class>ray.servlet.RequestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>REQ</servlet-name>
<url-pattern>/servlet/login.html</url-pattern>
</servlet-mapping>
</web-app>
/********************ERROR MESSAGE**************************************/

TTP Status 404 - /SERVLET/ray.servlet.RequestServlet

type Status report

message /SERVLET/ray.servlet.RequestServlet

description The requested resource (/SERVLET/ray.servlet.RequestServlet) is not available.
Sun-Java-System/Web-Services-Pack-1.4
/***********************************************/

please help
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't seem to understand what servlet mapping is.
Your form action must match one of the url pattern in your web.xml.
You've got only one pattern linked to your servlet : /servlet/login.html
 
tubu Ray
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So how do i do this
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
change ur web.xml as follows,

<url-pattern>/SERVLET/*</url-pattern>
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Match your form action (in the html file) to the appropriate url pattern.
You should add a url pattern in your web.xml.
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


<form action = "/SERVLET/ray.servlet.RequestServlet" method = "POST">



You got problem here. Modify this to


<form action = "servlet/login.html" method = "POST">
 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also in the servlet you have implemented only the doGet(), but in the html you are using POST method, so you have to implement doPost() also.

Hope this helps.
Thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic