0

First lets get the code out of the way.

index.html in WebContent

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Child Tickets</title>
</head>
<body>
<h1>Find all child tickets affected user and their info</h1>
<hr>
<form name="f1" method="GET" action="/FindChildTicket4/FindChildTickets">
<input type="text" name="masterticket">
<button type="submit" value="main" name="btnSubmit">Hello</button>
<br>
<br>
<div id="results">
results html
</div>
</form>
</body>
</html>

web.xml in WebContent/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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>HelloWorld</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

HelloAgain.java in Java Resources/src/hlo.hello.net

package hlo.hello.net;

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

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

    /**
     * @see HttpServlet#HttpServlet()
     */
    public HelloAgain() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

when I deploy this in Eclipse to the local Apache7 server the html fires off and when I click the Hello button I get back the "Served at: /HelloWorld" in the browser. Now when I push this to our internal Cloud Foundry setup VIA Eclipse I get this when I click on the Hello button

HTTP Status 404 - /HelloWorld/HelloAgain
type Status report
message /HelloWorld/HelloAgain
description The requested resource is not available.
Apache Tomcat/7.0.62

I have tried these sites... HTTP Status 404 - on Eclipse with Tomcat Java - Servlet 404 error Getting HTTP Status 404 error when trying to run servlet java servlet not found error 404 in eclipse

as well as a few others and non of the recommendations fixes the cloud foundry side. The HTML will work every singe time but it never finds the servlet. I also have looked at the cloud foundry server files I deployed and the class is there under WEB-INF/classes/hlo/hello/net/

Very odd. Also some of the recommendations in the linked sites broke the local apache deployemtn to where the server would shutdown. Just seeing if anyone has any insight since I cannot find any good data when searching for cloud foundry 404.

Community
  • 1
  • 1
reddragon72
  • 191
  • 1
  • 3
  • 16

1 Answers1

0

It appears that you're trying to access /HelloWorld/HelloAgain.

HTTP Status 404 - /HelloWorld/HelloAgain

Your Servlet is configured for /HelloAgain and /HelloWorld is the context (you can see this in the output from when you run locally, Served at: <context>).

When you deploy an application to a local Tomcat, it is typically done under a context and not the ROOT context. The difference is when you deploy to a context, everything is prefixed with that context name. When you deploy to Cloud Foundry, the Java build pack always deploys your application as the ROOT context. This means there is no prefix.

If you have hard coded URLs or links in your application that include the context name they will be incorrect when you deploy to CF and that would generate 404s.

One quick test would be to go to /HelloAgain when you deploy on CF. Since the app is deployed under the ROOT context, it should be accessible at that URL. I suspect you'll see "Served at: /" in the output.

One way to make sure URL's are generated correctly is with JSTL Core's <c:url> tag. Another way would be to build your URL's from parameters on the HttpServletRequest object. I'm sure there are many other ways. You just need to make sure the URL being used takes into account the context of where the application is being deployed.

Hope that helps!

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28