Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Trying to write a servlet, keep getting 404 errors in web browser.

  1. #1
    Member
    Join Date
    May 2013
    Posts
    106
    My Mood
    Amused
    Thanks
    16
    Thanked 9 Times in 9 Posts

    Default Trying to write a servlet, keep getting 404 errors in web browser.

    Hey guys,

    I'm usually pretty good with this stuff, but Servlets are kicking my ass. The logic all seems straightforward enough, but I can't figure out the environment.

    Here's my setup: running Tomcat through XAMPP and using port 9999. The files themselves are all in a Dropbox folder. So the root here is: C:\Dropbox\xampp\tomcat\webapps\servletprojects

    For this particular servlet, it's part of a larger project that also has some Javascript elements with some HTML pages and a style sheet. That is in:

    C:\Dropbox\xampp\tomcat\webapps\servletprojects\Hi gherNumbersProject

    Under that, I have the folder C:\Dropbox\xampp\tomcat\webapps\servletprojects\Hi gherNumbersProject\WEB-INF and within there I have C:\Dropbox\xampp\tomcat\webapps\servletprojects\Hi gherNumbersProject\WEB-INF\classes

    Inside the WEB-INF folder I have my web.xml file:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <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>ProcessLogin</servlet-name>
          <servlet-class>process_login</servlet-class>
       </servlet>
     
        <servlet-mapping>
           <servlet-name>ProcessLogin</servlet-name>
           <url-pattern>/process_login</url-pattern>
       </servlet-mapping> 
    </web-app>

    Inside the classes folder I have process_login.class

    And here is the code for my servlet. There's not much there yet, I just want to get text on the web browser screen.

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
     
    public class process_login extends HttpServlet
    {
    	 public void doGet(HttpServletRequest request, HttpServletResponse response)
    	         throws IOException, ServletException 
    	         {
    		 		PrintWriter out = response.getWriter();
     
    		 		out.println("Hello!");
    	         }
     
     
    }

    So then I tell Eclipse to build the file. It generates the process_login.class file. I can't figure out how to get Eclipse to put it into the \WEB-INF\classes folder... it puts it in the project's main folder C:\Dropbox\xampp\tomcat\webapps\servletprojects\Hi gherNumbersProject right next to the process_login.java file. I've just been copying the .class file over manually. Any advice on how to get Eclipse to put the .class file where I want it is appreciated. But that isn't my main issue.

    Lastly I point Firefox over to http://localhost:9999/servletproject.../process_login

    But all I get is a 404 page:

    HTTP Status 404 - /servletprojects/HigherNumbersProject/process_login

    type Status report

    message /servletprojects/HigherNumbersProject/process_login

    description The requested resource is not available.
    Apache Tomcat/7.0.30
    Am I fundamentally misunderstanding the setup of servlets? Or is there some mundane detail I am missing?

    This is really frustrating because I like to think I'm a pretty smart guy and I can figure this stuff out with enough effort, but I am absolutely hitting a wall here and burning off a lot of time. It's part of a larger class project which is due in 3 weeks. Though.... thank God I already got the Javascript, basic HTML layouts, and styling done. If I can clear this hurdle and just get the stupid servlets working I think I can plow through the internal code logic fairly quickly.
    Last edited by mstabosz; October 2nd, 2014 at 02:06 PM. Reason: Resolved Tomcat problem, erased from the post.


  2. #2
    Member
    Join Date
    May 2013
    Posts
    106
    My Mood
    Amused
    Thanks
    16
    Thanked 9 Times in 9 Posts

    Default Re: Trying to write a servlet, keep getting 404 errors in web browser.

    Disregard (dunno if anyone read this). I figured this out. Turns out you can only have one WEB-INF within a folder no matter how many different other folders within that folder.

Similar Threads

  1. Web Browser listening
    By badoumba in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 28th, 2013, 08:25 AM
  2. Replies: 3
    Last Post: March 4th, 2013, 12:58 AM
  3. Looking for web browser implemented in Java
    By nambill in forum AWT / Java Swing
    Replies: 3
    Last Post: March 19th, 2012, 05:37 AM
  4. Problem in designing Web Browser
    By Rupinder in forum Java Networking
    Replies: 2
    Last Post: January 29th, 2012, 08:18 PM
  5. How do I read browser cookies from a servlet?
    By diyaots in forum Java Networking
    Replies: 1
    Last Post: December 8th, 2011, 09:08 AM