1

I am trying to run a simple web-app with eclipse and tomcat 7. I an index html file with a text input and a submit button that calls on servlet.

I have created a Dynamic web project and have put the html (index.html) file in the WebContent folder.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>title</title>
</head>
<body>
    <form action="/TestServ" method="get">
        <input type="text" name="input">
        <input type="submit" value="Send it!">
    </form>
</body>
</html>

I have my package com.testing.web under /Java Rescources/src and in it my servlet (TestServ.java) which looks loke this:

@WebServlet("/TestServ")
public class TestServ extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public TestServ() {
        super();
        // TODO Auto-generated constructor stub
        System.out.println("AA%WU^SDJI&^R&KU");
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        System.out.println("AA%WU^SDJI&^R&KU");
    }
}

When i select Run->run on server on the project the index.html file loads just fine. The problem is that when i submit the form i get the following error page:

HTTP Status 404 - /TestServ

--------------------------------------------------------------------------------

type Status report

message /TestServ

description The requested resource is not available.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.34

I have searched and searched and haven't found a solution that helps me. Most answers around the web point to servlet url mapping mistakes. Note that i have tried many of them to no avail.

Furthermore i would like to add that my server is configured to use jdk1.7.0_10 in the runtime enviroments oprtion.

Finally, i do not understand why eclipse doesn't create the proper class/ structure under WEB-INF when the project is built.

I am totally buffled and any help will be much appreciated. Thank you very much in advance!

poussma
  • 7,033
  • 3
  • 43
  • 68
Humunculus84
  • 163
  • 2
  • 2
  • 7
  • whats your complete url ? – TheWhiteRabbit Jan 17 '13 at 04:51
  • If the application is properly deployed (that has to be checked in the logs), the url of your servlet is http://.../[name-of-the-war]/TestServ but double check you have not any issue in tomcat logs. BTW, do you see your "AA%WU^SDJI&^R&KU" in the output? – poussma Jan 17 '13 at 07:02
  • Thanks for the replies. Tech- my url is http://localhost:9999/TestProj/, which brings up the index.html and after that when i click on the submit button its: http://localhost:9999/TestServ?input= whixh gives me the error. – Humunculus84 Jan 17 '13 at 07:24
  • ZNK-M - I'm not sure how to check the logs of the server instance inside eclipse :/ On the other hand, my output message is shown in the console only if i do Run->run on server directly on the servlet file. When i go through the index and submit process it doesn't. – Humunculus84 Jan 17 '13 at 07:28

3 Answers3

4

Finally found the problem, and as usual it was the simplest thing.

The action in the form needed to be like this:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>title</title>
</head>
<body>
    <form action="/TestProj/TestServ" method="get">
        <input type="text" name="input">
        <input type="submit" value="Send it!">
    </form>
</body>
</html>

and the url mapping as follows:

<servlet>
    <servlet-name>TestServ</servlet-name>
    <servlet-class>com.testing.web.TestServ</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>TestServ</servlet-name>
    <url-pattern>/TestServ</url-pattern>
  </servlet-mapping>

frankly i don't perfectly understand why though. Shouldn't /Testproj be considered the root of the app anyway? :/ Anyway...

Humunculus84
  • 163
  • 2
  • 2
  • 7
  • 1
    This was the 7th *The requested resource is not available* SO question I read. Finally! **/TestProj/TestServ** not **/TestServ**. – OldCurmudgeon Aug 22 '13 at 21:53
0

in order to remove 404 error we have to check the web.xml and the url you are giving in the tab. url should be like http://<127.0.0.1:8080>//. if it is webservice application

-1

Nothing wrong with your server configuration. Need some modifications in web.xml file. Just try this!

  1. Open your "web.xml" file.
  2. Add these tags between "<display-name>" tag & "<welcome-file-list>" tag.

    <servlet> <servlet-name>TestServ</servlet-name> <servlet-class>TestServ</servlet-class> </servlet>

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

  3. Run your project and in browser enter URL as "http://localhost:8080/TestServ"

Hope it will work! :)

P.S. * You can actually use any name between "<servlet-name>" tags. But names in both places must be same.