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 8128395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:51:53+00:00 2026-06-06T07:51:53+00:00

Lets say that you have a following simple application: <form action=helloServlet method=post> Give name:<input

  • 0

Lets say that you have a following simple application:

<form action="helloServlet" method="post">

        Give name:<input type="text" name="name" />

        <input type="submit" value="Send"/>
</form>

And a servlet handling that form:

package org.servlets.hello;

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

@WebServlet(name="helloServlet", urlPatterns={"/helloServlet"})
public class helloServlet extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

    response.setContentType("text/html;charset=UTF-8");
String name = request.getParameter("name");


    PrintWriter out = response.getWriter();

    try {

        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet helloServlet</title>");  
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Hello  " + name + "</h1>");
        out.println("</body>");
        out.println("</html>");

    } finally { 
        out.close();
    }
} 

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
    processRequest(request, response);
}

}

Now this works perfectly when it is ran from a web page located at the “Web Pages” folder but when I try to do the same in a subfolder in Web Pages I am given 404 error (The requested resource () is not available.). Am I supposed to change something to make the subfolder a valid location to call for a servlet?

  • 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-06-06T07:51:56+00:00Added an answer on June 6, 2026 at 7:51 am

    If the POST action url starts with "/" it is absolute. Or else, it is relative to the current page

    Because the post url <form action="helloServlet" , helloServlet is relative to the current path.

    This is how the helloservlet url will be accessed:

              Current Page          Servlet URL
    Usage 1   /form.html            /helloservlet
    Usage 2   /subfolder/form.html  /subfolder/helloservlet
    

    And in your case, the Usage 1 works because Servlet is mapped to /helloservlet.

    Solution:

    Modify line

    <form action="helloServlet" method="post">

    to

    <form action="/{contextPath}/}helloServlet" method="post">

    I think your context path is not default "/" context path. In that case, you should be having url relative to the domain. Replace {contextpath} with the actual context path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a working form that looks like the following =form_for @survey
Lets say that I have the following code: public class Shelter<A extends Animal, B
Lets say that i have the following array : float QuadVertices[4 * 2]; float
I have an iframe which lets say that it contains the following text: <h1>
Lets say I have an array numbers that contains the following values: int numbers
Lets say that i have 2 pages: index.php and service.php index.php sends an http-post
Say I have a page in my web application that lets a user update
Lets say I have a schema that defines the following XML: <Values> <Add Key=Key1>Value
I have a simple photo taking application that has the following design: [Consider the
Let's say that I have the following code that's run in one thread of

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.