Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tomcat requested resource () is not available [duplicate]

i know its a very common question as i find many questions relating to this in several forums, including SO. but i have not found a solution yet my web.xml (located in WEB-INF)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>SMSProjectNew</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>ReceiveMessagesServlet</display-name>
    <servlet-name>ReceiveMessagesServlet</servlet-name>
    <servlet-class>com.sendreceive.ReceiveMessagesServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ReceiveMessagesServlet</servlet-name>
    <url-pattern>/ReceiveMessagesServlet</url-pattern>
  </servlet-mapping>
</web-app>

the html page index.html, located in WebContent folder

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
The application started successfully version 1:27
<form action="/ReceiveMessagesServlet" method="post">
<input type="text" name="number"/>
<input type="text" name="message"/>
<input type="submit" name="submit"/>
</form> 
</body>
</html>

finally the servlet, ReceiveMessagesServlet, located in src\com.sendreceive package com.sendreceive;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

   public class ReceiveMessagesServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public ReceiveMessagesServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request,response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request,response);
    }

    protected void processRequest(HttpServletRequest request,
            HttpServletResponse response) {
        String responseMessage = request.getParameter("message");
        String responseNumber = request.getParameter("number");
        System.out.println(responseMessage+responseNumber);
    }

}

i have installed the tomcat plugin in eclipse. when i right click on the project and then click on run the project on server. tomcat server starts in eclipse and the index.html page is shown..but when i enter some values in the fields and click submit..it gives the 404 error..i have been struggling from past 2 hours..kindly help..also..fyi, i am using this tutorial http://www.ibm.com/developerworks/opensource/library/os-eclipse-tomcat/index.html

like image 329
i_raqz Avatar asked Feb 21 '11 06:02

i_raqz


People also ask

How many requests per second can Tomcat handle?

The default installation of Tomcat sets the maximum number of HTTP servicing threads at 200. Effectively, this means that the system can handle a maximum of 200 simultaneous HTTP requests.

How do I Fix error 404 in Tomcat in linux?

This error indicates that the server could not find the desired resource. This resource can be any file such as JSP, HTML, or image resource. Usually, the resource is present, but it is referenced incorrectly. In most cases, you can fix this by correcting the URL.


1 Answers

You are getting 404 error because of the action="/ReceiveMessagesServlet", please remove the slash. Try with action="ReceiveMessagesServlet".

When you add a slash to URL pattern then the container will look for a web application deployed with name 'ReceiveMessagesServlet'.Since this not there you will receive 404 error.

like image 154
donatello Avatar answered Sep 24 '22 15:09

donatello