Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem: requested resource not available

 
in.anurag Singh
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is my first Servlet Program and i am not able to sort out the problem..here it is:
I am using Tomcat 5.5 for this..

This is my html page at
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\beer


This is my DD File as web.xml at
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\beer\WEB-INF


This is the code of my servlet class "beerselect.java". The beerselect.class file is kept at
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\beer\WEB-INF\classes\com\example\web

package com.example.web;

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

public class beerselect extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("beer selection<br>");
String c=request.getParameter("color");
out.println("<br>got beer color "+c);
}
}

This all is the hierarchy where i have put up my files.
Now i have started apache tomcat 5.5 and wrote in the browser
http://localhost:8080/form.html
then my form APPEARS.
when i select an option and click on button, I get an error:

HTTP Status 404 - /beer/selectbeer.do
type: Status report

message: /beer/selectbeer.do

description: The requested resource (/beer/selectbeer.do) is not available.

Now, I engaged all my mind in resolving the error, but can't sort out that.
So, I request you to have a look and sort out my problem..
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're deploying to the ROOT context then your classes should be in ROOT/WEB-INF/classes. Right now it looks like you couldn't decide if you wanted to deploy to root or to beer, so sort of did both. But it won't work like that :)
 
in.anurag Singh
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I couldn't understand the meaning of ROOT CONTEXT. will anyone please elaborate this. and what will be the difference if i deploy it to the ROOT directory.
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take your beer folder from ROOT and put it in webapps, it should work...

ROOT Context means, ROOT is the project folder(like how beer is for your project now..). If you deploy it to ROOT directory, you should put all your classes in ROOT/WEB-INF/classes folder..
 
in.anurag Singh
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
the issue is resolved.
Simply i put my beer folder in webapps, and it worked.
but one thing , i am not able to understand..that earlier when my beer folder was in folder webapps/root/, then i was typing in the browser:
http://localhost:8080/beer/form.html

and this time when i put my beer folder in webapps, then also i am typing the same thing

http://localhost:8080/beer/form.html

and the tomcat is successful in finding the form file..so, how is this possible..
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
webapps is the deploy folder of tomcat, which means, http://localhost:8080/beer/form.html will search for beer inside webapps, and then locate the form.html inisde beer.. if you put your beer inside Root, beer will not be an deployable project...
 
in.anurag Singh
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But,

when my beer folder was in folder webapps/root/, then i was typing in the browser:
http://localhost:8080/beer/form.html

and my form.html page was also appearing..
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://localhost:8080/beer/form.html

In Tomcat, ROOT is mapped to /, so in the above URL, /beer/form.html will be searching for beer inside ROOT and form.html inside beer, which is there so, it will present you the html. As, I told you, since it is not a deployable project, server will not register the servlets written by you inside that folder, so you get resource not found exception...
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic