aspose file tools*
The moose likes Servlets and the fly likes 404 Not Found - Servlet runs locally (GlassFish), but Not Found on web site Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "404 Not Found - Servlet runs locally (GlassFish), but Not Found on web site" Watch "404 Not Found - Servlet runs locally (GlassFish), but Not Found on web site" New topic
Author

404 Not Found - Servlet runs locally (GlassFish), but Not Found on web site

Josef Stern
Greenhorn

Joined: Mar 26, 2011
Posts: 9
I am an advanced beginner in Java, but an utter beginner when it comes to deploying servlets. I can get a simple doPost servlet to run on my local machine, but when I deploy the .war file to my real web domain, I always get the error message:

404 Not Found
The requested URL /natal/ClassA was not found on this server.

My initial suspicions were that the doPost action of my HTML form did not properly match the settings of my web.xml file, but I have tried so many combinations that I suspect that the problem is something else.

I am developing on NetBeans 6.9.1. I am using GlassFish Server 3 (not Tomcat). My ISP says that I have the necessary permissions to run servlets on my web site. In creating this servlet class, the project-package-class structure is:

ProjectA -> PackageA -> ClassA

The form calling the servlet has HTML code:

***************************************************************
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="ClassA" method="post" name="TestA">
<input name="Button" type="submit" value="PleaseWork" /></form>
</body>
</html>
***************************************************************

though I have tried many different actions such as "PackageA/ClassA", "ProjectA/PackageA/ClassA", "./zapp/ClassA" (I want to put the servlet in a directory /zapp).

/natal has chmod permission 755
/natal/zapp has 755
/natal/testa.html has 644
/natal/zapp/ProjectA.war has 755

I have tried many variations of web.xml, but here is the default that GlassFish created for me (I had to explictly ask for its creation, it did not happen by default). I always kept servlet-name as ClassA, but have varied the URL-pattern (mostly) and servlet-class (occasionally).

**************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>ClassA</servlet-name>
<servlet-class>PackageA.ClassA</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ClassA</servlet-name>
<url-pattern>/ClassA</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
**************************************************************

The servlet code, which is created by default:
*************************************************************
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package PackageA;

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

/**
*
* @author Josef Stern
*/
public class ClassA extends HttpServlet {

/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
/* TODO output your page here */
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet ClassA</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet ClassA at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
/* */
} finally {
out.close();
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

}
*************************************************************

When I re-create the .war file, I invoke the Run -> Clean and Build Main Project menu. I then ftp the ProjectA.war file to .../natal/zapp on my website. The HTML form, testA.html, resides in .../natal, and I want it to call the servlet in .../natal/zapp/ProjectA.war.

I know that the browser senses the presence of the .war file because when I enter this URL directly into the browser:

http://my-web-domain-reaching-to/natal/zapp/ProjectA.war

the browser wants to "open" it, and asks whether I want to open or save it, and what application I should use to open it.

I can get this servlet to run on my local machine if I directly enter this url in the browser:

http://localhost:8080/ProjectA/PackageA/ClassA

and have the web.xml settings:

<servlet>
<servlet-name>ClassA</servlet-name>
<servlet-class>PackageA.ClassA</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ClassA</servlet-name>
<url-pattern>/PackageA/ClassA</url-pattern>
</servlet-mapping>

Assuming that these web.xml settings are correct, I have tried form actions of

ClassA
PackageA/ClassA
ProjectA/PackageA/ClassA
./zapp/ClassA
./zapp/PackageA/ClassA
./zapp/ProjectA/PackageA/ClassA

on the web site, but all generate the same error message, though the messages reference different url's.

I am at my wit's end. The odds are that I am missing something fundamental, and I will be embarassed when I learn the solution. There is also a possibility that GlassFish is doing something non-standard (I have to explicitly create web.xml files, they do not happen automatically). I could still be missing the exact form action & web.xml settings that would work, but I have tried so many variations that I now doubt that this is the problem. If it is not a fundamental mistake on my part, my wild guess would be that NetBeans/GlassFish have not put their files in the expected directories on my machine.

I have checked around 50 relevant web pages, but none have helped me solve this. This forum seems the clearest and most helpful to in other issues that I have faced.

I would appreciate any information, suggestions, or debugging techniques. Thank you to all who reply.

Josef

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

Hmmm, I'm trying to look at your code, but the stubborn forum software has made it look all wonky. If you use CODE tags when posting code to the forums (see the FAQ at ⇒ UseCodeTags ⇐) they tell it "Hey! Keep your hands off my formatting!" and your code will look just like when you cut and pasted it into the reply. Cool, no?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

I then ftp the ProjectA.war file to .../natal/zapp on my website.

What significance does this folder have? I don't use Glassfish so I have no idea. Is this a folder that Glassfish is expecting war files to be placed in?
Josef Stern
Greenhorn

Joined: Mar 26, 2011
Posts: 9
Bear,

Thank you for the prompt response. I enclose the code below.

The .../natal/zapp folder has no special significance, at least not to GlassFish. natal & zapp are the arbitrarily-named folders on my web site. /natal is where testa.html resides. testa.html contains the form that issues the doPost. /natal/zapp is a folder subordinate to /natal. /natal/zapp is where I put the .war file. So:

/natal/testa.html

sends the doPost (action="ClassA") to

/natal/zapp/ProjectA.war

I can place the .war file in another location, if necessary, though I would prefer not to have it in the same folder as testa.html.

Thanks,
Josef


/natal/testa.html form, does doPost
************************************************



default web.xml file, modified about 50 times
************************************************




servlet code, ClassA, within PackageA, essentially created by default through NetBeans. I am not actually using the doPost function at this point. I just want the servlet to respond to the html.
************************************************




settings of the web.xml file when I get everything to run properly locally
************************************************







Josef Stern
Greenhorn

Joined: Mar 26, 2011
Posts: 9
I have been thrashing away at this with little progress. After many combinations of form action, url-mapping, method=post vs. no method, and placing the ProjectA.war in different locations, I still get the 404 Not Found error message.

One item made a difference, but it is still not helpful for me. I created a directory /ClassA beneath /natal, and then put ProjectA.war into that directory, so that I have:

…/natal/ClassA/ProjectA.war

Where …/natal/testa.html contains the form that tries calling for ClassA

Now, most of my combinations give me the error message: 403 Forbidden, You don’t have permission to access … on this server. If I deliberately enter a misspelling into my form action statement (asking for ClassB, which does not exist), then I revert back to the 404 Not Found error. This tells me that the form action “finds” the servlet in /natal/ClassA, but now I face a different problem. The chmod permissions on /ClassA and ProjectA.war are 755, so chmod should not be an issue.

If I unzip/decompose my ProjectA.war file, I get:

ProjectA/WEB-INF/classes/PackageA/ClassA.class

which seems correct to me.

Rather than thrash about with my specific situation, it might be more constructive if someone could explain the relationship among these components, or give an example:

The contents of action=”Call.A.Servlet” in a form that does a doPost
web.xml servlet-name
web.xml servlet-class
web.xml url-mapping
The directory in which the .war file resides

An example where each of these is well-defined would probably help me. I have read a few posts that state that the form action should be the same as the url-mapping. I tried that, but it does not seem to work for me (though I could be missing something fundamental). Other sources or posts do not explicitly declare that form action == url-mapping.

Thanks,
Josef


Josef Stern
Greenhorn

Joined: Mar 26, 2011
Posts: 9
I am sorry to resurrect an old thread, but I thought that I should bring closure to it. My experience may help somebody else.

The problem was my ISP. They did not support Java servlets for web sites. I asked their tech support people about this several times, and they assured me (through terse responses), that they supported servlets. I had to grill them on the details of just how they deploy Java. When forced to provide details about their deployments, they finally confessed that they offer no such service.

The ISP was Speakeasy, and I am sorry to leave them. I have moved to Kattare, and I hope this works out.

Josef
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

What, did they think that you wouldn't notice?

Customer: "Do you serve steak?"
ISP: "Yes, we do!"
Customer: "OK, I'll take the steak,"
ISP: (serves the customer an old boot)
Customer" "Hey! This isn't steak, it's an old boot!"
ISP: "Oh crap! He noticed!"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 404 Not Found - Servlet runs locally (GlassFish), but Not Found on web site