Results 1 to 10 of 10
  1. #1
    jocdrew21 is offline Senior Member
    Join Date
    Jan 2014
    Posts
    137
    Rep Power
    0

    Default First JSP program and I am going in circles

    Ok I really need advice. I have read several posts on stack overflow and from a few other places and I am getting nowhere. First I was getting a bunch of errors and but I found out I needed to add the servlet jar file and I was about in the clear. However I was still getting a 404 error.

    Now I am getting a error saying port 8080 is already in use. I tried to kill it in the terminal (using a mac) but pretty sure I was doing it wrong. Therefore I decided to restart the computer, I ran the program again, it started up but the tomcat browser never ran. I hit run again and the darn J2EE port 8080 error came.

    I just started jumping into javaEE and this is SO frustrating. Please help

    Java Code:
    package demo;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Servlet implementation class Demo
     */
    public class Demo extends HttpServlet {
    	private static final long serialVersionUID = 1L;
    
        /**
         * Default constructor. 
         */
        public Demo() {
            // TODO Auto-generated constructor stub
        }
    
    	/**
    	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		PrintWriter out = response.getWriter();
    		 out.println("<h1>Hello, world!</h1>");
    	      // Write the response message, in an HTML page
    	      try {
    	         out.println("<!DOCTYPE html>");
    	         out.println("<html><head>");
    	         out.println("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
    	         out.println("<title>Hello, World</title></head>");
    	         out.println("<body>");
    	         out.println("<h1>Hello, world!</h1>");  // says Hello
    	         // Echo client's request information
    	         out.println("<p>Request URI: " + request.getRequestURI() + "</p>");
    	         out.println("<p>Protocol: " + request.getProtocol() + "</p>");
    	         out.println("<p>PathInfo: " + request.getPathInfo() + "</p>");
    	         out.println("<p>Remote Address: " + request.getRemoteAddr() + "</p>");
    	         // Generate a random number upon each request
    	         out.println("<p>A Random Number: <strong>" + Math.random() + "</strong></p>");
    	         out.println("</body>");
    	         out.println("</html>");
    	      } finally {
    	         out.close();  // Always close the output writer
    	      }
    	}
    
    	/**
    	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    	}
    
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,963
    Rep Power
    31

    Default Re: First JSP program and I am going in circles

    Also posted at: First JSP program Error
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,225
    Rep Power
    13

    Default Re: First JSP program and I am going in circles

    How long have you been working on this?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    jocdrew21 is offline Senior Member
    Join Date
    Jan 2014
    Posts
    137
    Rep Power
    0

    Default Re: First JSP program and I am going in circles

    about 5 hours.

  5. #5
    jocdrew21 is offline Senior Member
    Join Date
    Jan 2014
    Posts
    137
    Rep Power
    0

    Default Re: First JSP program and I am going in circles

    if I type http://localhost:8080/ into my browser I get the original error:

    [code-java]
    Error 404 - Not Found

    No context on this server matched or handled this request.
    Contexts known to this server are:
    Deployment(/Deployment)
    [/code]

    I do not know why this is so difficult... I am going off a tutorial here and hit a wall.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,225
    Rep Power
    13

    Default Re: First JSP program and I am going in circles

    Well, that is not really that much time. I presume you have gone thru lots of tutorials and hopefully read a book (or perhaps two) on JSP programming as well as the related Tomcat documentation. It takes a lot of time to get familiar with all of this. I suggest you check out the following site as the tutorials (at least on JSP) are pretty good.

    Coreservlets.com: Java, JSF 2, PrimeFaces, Ajax, jQuery, Spring, Hibernate, REST, Hadoop, and GWT Training, Tutorials, Consulting, Books, & Resources

    And even though I have done this before I haven't done it recently so I would have to review it to help you and that could take a while. I am certain others on this forum could provide more immediate assistance.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    jocdrew21 is offline Senior Member
    Join Date
    Jan 2014
    Posts
    137
    Rep Power
    0

    Default Re: First JSP program and I am going in circles

    Thank you for the link. I changed computers to see if I did something wacky with installing JavaEE on eclipse. Pulled the same code and ran it and nothing displayed is the browser. I know 4 hours is not a lot of time when looking at the topic, for the issue I am having it is.

    At least on my iMac the java Icon is displayed at the bottom much like it would if I was running a swing application. I can simply close it and the server closes. I am just baffled because it was working then all of a sudden it stopped.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,963
    Rep Power
    31

    Default Re: First JSP program and I am going in circles

    What file is the server looking for and not finding?
    If you can't figure out where the server is looking for the file it's not finding, one method is to put a copy of the file in all possible places it could look with the file's contents saying where it was loaded from.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    jocdrew21 is offline Senior Member
    Join Date
    Jan 2014
    Posts
    137
    Rep Power
    0

    Default Re: First JSP program and I am going in circles

    Weird I was just frustrated and decided to take a break. I woke up this morning and decided to tackle it again and everything worked perfectly.

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    11

    Default Re: First JSP program and I am going in circles

    Quote Originally Posted by jocdrew21 View Post
    I do not know why this is so difficult...
    You already answer it yourself:

    I am going off a tutorial here
    You should be using -quality- sources of information - namely a good book.

    Books are not going to solve problems with development environments though.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Drawing concentric circles
    By jazzo in forum New To Java
    Replies: 7
    Last Post: 02-07-2013, 03:01 PM
  2. finding the overlap of two circles
    By aortell24 in forum Java 2D
    Replies: 6
    Last Post: 06-10-2012, 05:03 AM
  3. Help determining if Circles overlap
    By quinnvanorder in forum New To Java
    Replies: 18
    Last Post: 04-22-2012, 06:58 AM
  4. Draw circles, select circles
    By cselic in forum Java 2D
    Replies: 2
    Last Post: 05-17-2010, 02:02 PM
  5. Circles (Loops)
    By Zebra in forum New To Java
    Replies: 1
    Last Post: 05-29-2008, 06:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •