Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6620921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:10:12+00:00 2026-05-25T21:10:12+00:00

I am working on a project for school and am completely frustrated. The project

  • 0

I am working on a project for school and am completely frustrated. The project is to get a simple JSP/Servlet demo working on our personal websites and after probably 20+ hours of work I am still unsuccessful in getting this accomplished. The really frustrating thing I’ve been given all the code and still can’t really get this to work. Well, that isn’t totally true. I have gotten it to work on my local tomcat server, but I can’t replicate that magic on my personal website. So, here is what I have.

First, the code. This assignment consists of two classes for servlets and two jsps and a web.xml file.

Here is the first servlet called ControllerServlet.java

 package test;

    // Import the servlet classes
    import javax.servlet.*;
    import javax.servlet.http.*;

    // Import the standard Java classes
    import java.io.*;
    import java.util.*;

     /**
    * Controller Servlet
    */
    public class ControllerServlet extends HttpServlet
    {
      private static String HELLO_JSP = "hello.jsp";
    private static String GOODBYE_JSP = "goodbye.jsp";
    private static String OTHER_JSP = "main.jsp";

     public void init() throws ServletException
    {
      // Typically initialize your request to page mappings here
    }

    public void service( HttpServletRequest req, HttpServletResponse res ) throws     ServletException
    {
    try
     {
      // Get the path - this is our key to our Request map
      String pathInfo = req.getPathInfo();

      // Find out what the user is requesting 
      String jsp = null; 
      if( pathInfo.equalsIgnoreCase( "/hello" ) )
      { 
        String name = req.getParameter( "name" );
        PersonBean person = new PersonBean( name );
        HttpSession session = req.getSession();
        session.setAttribute( "person", person );
        jsp = HELLO_JSP;
      }
      else if( pathInfo.equalsIgnoreCase( "/goodbye" ) )
      {
        HttpSession session = req.getSession();
        PersonBean person = ( PersonBean )session.getAttribute( "person" );
        req.setAttribute( "person", person );
        session.removeAttribute( "person" );
        jsp = GOODBYE_JSP;
      }
      else
      {
        jsp = OTHER_JSP;
      }

      // Foward the request to the jsp
      RequestDispatcher dispatcher = req.getRequestDispatcher( "/" + jsp );
      dispatcher.forward( req, res );
    }
    catch( IOException ioe )
    {
      throw new ServletException( ioe );
    }
    }
    }

Now the PersonBean.java:

package test;

 public class PersonBean implements java.io.Serializable
 {
 private String name;

public PersonBean()
{
}

public PersonBean( String name )
{
  this.name = name;
}

public String getName()
{
  return this.name;
}

public void setName( String name )
 {
  this.name = name;
}
}

Now the hello.jsp:

<jsp:useBean id="person" class="test.PersonBean" scope="session" />


<HTML>
  <HEAD>
  <TITLE>Hello, <jsp:getProperty name="person" property="name" /></TITLE>
 </HEAD>
 <BODY>
  <P>Hello, <jsp:getProperty name="person" property="name" /></P>
  <A HREF="goodbye">Goodbye</A>
</BODY>
</HTML>

And the goodbye.jsp

 <jsp:useBean id="person" class="test.PersonBean" scope="session" />

   <HTML>
     <HEAD>
      <TITLE>Good bye, <jsp:getProperty name="person" property="name" /></TITLE>
    </HEAD>
    <BODY>
      <P>Good bye, <jsp:getProperty name="person" property="name" /></P>
    </BODY>
    </HTML>

Lastly my web xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>deploy</display-name>
    <servlet>
        <description>
        </description>
        <display-name>ControllerServlet</display-name>
        <servlet-name>ControllerServlet</servlet-name>
        <servlet-class>test.ControllerServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ControllerServlet</servlet-name>
        <url-pattern>/testing/*</url-pattern>
    </servlet-mapping>

</web-app>

My web server’s file manager has a folder called WEB-INF under the public_html section so in that file folder I placed the two jsps and the web xml file. Under that was a preexisting folder called classes which I made a new folder in called test and in that folder placed the two class files. I would think that going to mysite.com/testing/hello?name=Bradley would result in the correct thing happening, but unfortunately I get a 404 error saying that url testing/hello is not found.

Does anyone have any suggestions as to why and can’t make this happen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:10:13+00:00Added an answer on May 25, 2026 at 9:10 pm

    The servlet class declaration in web.xml is wrong. You’re put ControllerServlet in a package test. So the proper servlet class declaration should be:

    <servlet-class>test.ControllerServlet</servlet-class>
    

    How you got it to work at local environment is beyond me. Perhaps the package was initially not there at all, or perhaps you removed the package from the servlet class declaration, or perhaps you’ve 2 servlet classes in both the default and test package.


    Update: based on the code given as far (and assuming that you fixed the servlet declaration in web.xml), here’s how the folder structure should look like:

    public_html 
     |-- WEB-INF
     |    |-- classes
     |    |    `-- test
     |    |         |-- ControllerServlet.class
     |    |         `-- PersonBean.class
     |    `-- web.xml
     |-- goodbye.jsp
     |-- hello.jsp
     `-- main.jsp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our team is currently working on completely redesigning our school's website and one of
I am working on a school project in C++ and am using our schools
I'm working with an application right now for our project in school. My application
I am working a school project to implement a Huffman code on text. The
I'm working on a project for school, and I'm implementing a tool which can
I am working for a project at school regarding face detection, based on a
while working on a school project i ran into a problem using javascript to
Im working on a school project and it's my first time on android development.
I'm working on a school project and I'm getting some weird errors from Xcode.
I am currently working on a school project and I'm not sure what is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.