Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

cant run my servlet through webpage

  Asked By: Jaxson    Date: Feb 02    Category: Java    Views: 752

I have installed on my computer a Tomcat web server 4.2; (properly
configured; because i could view .html, .jsp and .class files in the
webapp/ROOT/.. folder).

I want to create my own context root - i made one called "params"
in the "webapp" directory of my Tomcate installation, created two
subdirectly underneath (/params/WEB-INF and /params/ servlets) i
placed my "MakingGet.html" file in /params/servlets/ placed
my "web.xml" file in /params/WEB-INF and place my class
file "MakingGet.class" in directory /params/WEB-INF/classes/.
I have two problem
1. when i load the webpage with
http://localhost/params/servlets/MakingGet.html the page loads but
If i click submit the button doesn't do anything. (this is the most
disturbing). i have tried to put the complete url in the action
attribute of the form but it just didn't work.
I have attempted to run the class in /webapp/ROOT/WEB-INF/classes
using http://localhost//servlets/MakingGet and it showed that the
class is working fine; the class still did not load from the web
page (when i clicked submit) even when i put the complet url in the
action attribute of the form (i.e

2. I have an alias i defined in my web.xml file called " paraform".
when i try to load using http://localhost/params/paraform, the page
didn't load.

I have stopped and restarted the webserver a million time without
any change.Please help me out; i have been on it for two days now.

This is my web.xml code

<?xml version="1.0" encoding="UTF-8">
<!DOCTYPE web-app PUBLIC "-//Sun Microsystem Inc.//DTD Web

Application 2.2//EN"

Jeslob Anyware Java Server Page Test


This program test the use of three parameters
sent to the server machine.

<servlet-name> paraform</servlet-name>

"paraform" is the servlet alias while the
class name is MakingGet

<servlet-class> MakingGet </servlet-class>



<servlet-name> paraform <servlet-name>
<url-pattern> /paraform <url-pattern>



<!DOCTYPE HTML PUBLIC "-//W3C// DTD HTML 4.0 Transitional //EN">
<title> Collecting Three Parameter</title>

<h1 align="center"> Music Collection Extractor </h1>

<form action="/params/paraform" method="get" >

Album title <input type="text" name="param1"> <p>
Album Category <input type="text" name ="param2"> <p>
Artist Name<input type="text" name="param3"> <p>
<input type="button" value="SUBMIT">

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

public class MakingGet extends HttpServlet{

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{

PrintWriter out= response.getWriter();

String title= "Music Collection Extractor";

out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD
HTML 4.0 Transitional //EN \">");
out.println("<html><head><title>" +title
+ "</title></head> out.println("<h1 align=center>"+
title + "</h1> \n");
out.println("<ul> \n");
out.println("<li> Param1 </li>"+
("param1") + "\n"+
"<li> Param2 </li>"+
("param2") + "\n"+
"<li> Param3 </li>"+
("param3") + "\n"+
"</ul> \n"+




4 Answers Found

Answer #1    Answered By: Rosie Hughes     Answered On: Feb 02

why dont u use an IDE? using an IDE makes u free of setting this much
of details for setting up a web  based application.

Answer #2    Answered By: Freya Brown     Answered On: Feb 02

first remove any space in xml  data elements(for example <servlet-name> paraform</servlet-name> is wrong)

second remove webapp name from form  element (right syntax:<form action="/paraform" method="get" >

Answer #3    Answered By: Dep Tran     Answered On: Feb 02

I think i will resolve to IDE; i actually also use the IDE which comes with J2EE package which runs my servlet  and JSP; but i don't know how to interface a web  page with it; if you use thesame IDE can you tell me how; or better still, can you advice me the best IDE i could use.

Answer #4    Answered By: Cesara Fernandez     Answered On: Feb 02

sun IDEs are not user friendly. they are just good samples of java/j2ee programming ! the best IDE for servlet  works is jbuilder. it is powerfull and simple. it also has a built-in tomcat  configured in it. u also can use jdeveloper from oracle or websphere.
Intellij idea is also a good ide but u have to add a server  to it.
i myself use jdeveloper. u may download it from oracle for free.

Didn't find what you were looking for? Find more on cant run my servlet through webpage Or get search suggestion and latest updates.