Jsp Servlet

Iam new to the servlet .the following code are listed below

File Name is : Sampleservletexample.java

import java.io.*;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class Sampleservletexample extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet

{

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("<title>Example</title>" +"<body bgcolor=FFFFFF>");

out.println("<h2>The Value is</h2>");

String DATA = request.getParameter("messages");

out.println(DATA);

out.close();

}

}

the following html i have written

<html>

<head>

<title>Sample</title>

<body>

<form method="POST" action="\Sampling">

Messaging<select name="messages">

<option value="rummymanager">RummyManager</option>

<option value="rummyrefree">RummyRefree</option>

<option value="rummymovemanager">RummyMoveManager</option>

</select>

<input type="Submit" value="Submit">

</form>

</body>

</html>

the following things i have written in web.xml

<servlet>

<servlet-name>Sampling</servlet-name>

<servlet-class>Sampleservletexample</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Sampling</servlet-name>

<url-pattern>/Sampling</url-pattern>

</servlet-mapping>

Iam not able to retrieve the value which is given in the html

[1936 byte] By [dilipsrma] at [2007-11-27 4:32:34]
# 1

<form method="POST" action="\Sampling">

Change that to this:

<form method="POST" action="Sampling">

if it still doesn't work (you probably get an error "resource not found", it would help to be more specific in future posts) then you may need to put your servlet in a package.

gimbal2a at 2007-7-12 9:42:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
I have made changes,The Error what u have told is sameI cannot understand the package to be put into servlethelp with sample code
dilipsrma at 2007-7-12 9:42:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

What gimbal meant was your servlet should be in the package.

import java.io.*;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class Sampleservletexample extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet

{

should be

package com.sun.edu.scjd; // you can write any name

import java.io.*;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class Sampleservletexample extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet

{

AnanSmritia at 2007-7-12 9:42:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
thankx for ur replynow iam getting different errorjavax.servlet.ServletException: Error allocating a servlet instancejava.lang.NoClassDefFoundError: Sampleservletexample (wrong name: sample/Sampleservletexample)please help it what i shall do
dilipsrma at 2007-7-12 9:42:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

<servlet>

<servlet-name>Sampling</servlet-name>

<servlet-class>sample.Sampleservletexample</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Sampling</servlet-name>

<url-pattern>/Sampling</url-pattern>

</servlet-mapping>

update your web.xml and try. I am not sure about the syntax of <servlet-class>. I have just written package.servlet name.

AnanSmritia at 2007-7-12 9:42:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...