This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

404 Error- Please check the code for errors  RSS feed

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am refreshing my servlets/struts knowledge after a long time, I didnt found anything wrong with the following code. Anyone please cross verify and let me know the error. I am getting 404 when calling the URL,
http://localhost/simple.do

Class file,
package com.test.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SimpleServlet
extends HttpServlet {

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
System.out.println("Servlet called");
RequestDispatcher dispatcher = req.getRequestDispatcher("test.jsp");
dispatcher.forward(req, res);
}
}

JSP file,

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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>Arunan</title>
</head>
<body>

</body>
</html>

Web.xml,
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>simple</display-name>

<servlet>
<servlet-name>simple</servlet-name>
<servlet-class>com.test.servlet.SimpleServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>simple</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

</web-app>
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing I would check is the log files.

The servlet container responds 404 if there is no corresponding web app. Could be due to your servlet init() failing which would log an exception.

Bill
 
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your localhost is probably not running on port 80. Try using http://localhost:8080/simple.do

I'm not sure about the url-pattern in your servlet-mapping because I don't use Struts or global servlet mappings, but double-check that to see if there should be a leading slash.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Arunan Ramanathan wrote:
RequestDispatcher dispatcher = req.getRequestDispatcher("test.jsp");



This might also be a problem. Try using a full path. The 404 might be because it's not finding this file, not because it's failing to find the servlet.
 
Arunan Ramanathan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for your inputs

1. Port is not the problem
2. JSP is not the problem, since the println statement before the RequestDispatcher is not working

Confused!
 
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I don't see any context root of the application in URL.

What is the context root of your application deployed on the server?
What is the directory name in which application is deployed?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!