Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem using java servlets  RSS feed

 
mandeepsangwan kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want servlet to be called when i click on submit button
my html code is


<html>
<body>
<center>
<form name="Form1" method="post" action =http://localhost:8080/server/MyServlet1>
<B>Color:</B>
<select name="color" size="1">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br><br>
<input type=submit value="Submit">
</form>
</body>
</html>



and my web.xml code is


<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<welcome-file-list>
<welcome-file>ColorGet.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>MyServlet1</servlet-name>
<servlet-class>MyServlet1</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MyServlet1</servlet-name>
<url-pattern>/MyServlet1</url-pattern>
</servlet-mapping>

</web-app>

my java code is

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet1 extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
String color=request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<b>The select color is :");
pw.println(color);
pw.close();
}
}


im getting error when click on submit button

type Status report

message /server/MyServlet1

description The requested resource (/server/MyServlet1) is not available.



please help me fast
thank you
 
mandeepsangwan kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im using tomcat 7 and when i run the servlet its running

http//localhost:8080/MyApp/MyServlet1

its working but when click on submit button of html file it shows error

I have put html file in MyApp Folder and xml file in MyApp\WEB-INf and MyServlet.class file in classes folder and
MyApp is in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps
please help me out
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Is your web app called "server"? Otherwise that would not be the right URL to use.

As an aside, you should put all your classes into packages. You will run into problems eventually if you don't.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the servlet its running http//localhost:8080/MyApp/MyServlet1

I guess that answers that :-)
 
mandeepsangwan kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The wholse work is in MyApp folder sir
 
mandeepsangwan kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much
the answer was i should have put the whole work in server folder and remove the post method thank you
whole day gone
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!