Results 1 to 11 of 11

Thread: Design issues, need advice.

  1. #1

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Exclamation Design issues, need advice.

    I am having problems with adding a servlet to a program that I have written previously. Its not the servlet that is throwing me for a loop, its when I need to check to see if the appointment I am adding to the list is the same time as another appointment in the list.

    Here is what I want to do, just so you know.

    Have the user enter the information for one appointment and add it to the list, if that time is available.

    Show the results.

    If the date/time is unavailable, redirect to an error JSP.
    You will notice in my ApptServlet.java, I have commented out a few lines of code related to the checking to see if the date is taken or not.

    Code:
    			if(pl.isTaken(appt))
    			{
    				RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Error.jsp");
    				dispatcher.forward(request, response);
    			}//end if
    			else
    			{
    				List plist = pl.getPatientList();
    				request.setAttribute("plist",plist);
    				RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Results.jsp");
    				dispatcher.forward(request, response);
    			}//end else
    What I want to do is, in the ApptServlet.java if the date is taken, redirect to the Error.jsp. Else, set the patientList to the request object then redirect to the Results.jsp.

    I am trying to use an If Else statement to sort this out. I am using a method called isTaken() that checks the date of the appointment object that I want to add to the list against the dates of the appointment objects already in the list.

    The problem is I dont know how I should this in the following method. If the date is taken, I want to redirect to the error.jsp, but how would I do that.

    Code:
    	public void setAppointments(String n, int pID, boolean apptReason, int year, int month, int date, int hourOfDay, int minute)
    	{
    		//Create an new appointment object then add the appointment to the list
    		Appointment appt = new Appointment(n, pID, apptReason, year, month, date, hourOfDay, minute);
    		
    		//check to see if the appointments date = the date of another appointment
    		//Can I do something to foward the request dispatcher here if I extend HTTPServlet?
    		if(pl.isTaken(appt))
    		{
    		//I want to redirect to the error.jsp
    		}
    		else
    		{
    			patientList.add(appt);
    		}
    	}
    I have included my full code in a zip file.
    Otaku no Kamisama – God of the Geeks

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Design issues, need advice.

    Mark your method to throw an Exception with the message "appt taken" for example and catch it in the main ServLet class.
    if Exception caught and with the same body then redirect to the "error.jsp"
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Re: Design issues, need advice.

    Quote Originally Posted by ComputerJy
    Mark your method to throw an Exception with the message "appt taken" for example and catch it in the main ServLet class.
    if Exception caught and with the same body then redirect to the "error.jsp"
    Could you give me an example of what you mean? Do you mean to throw and exception i nmy PatientList.setAppointments(). What exception would I have to catch in my servlet?
    Otaku no Kamisama – God of the Geeks

  4. #4

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Re: Design issues, need advice.

    Isnt using exceptions like that really abusing exceptions and not the correct way to code? Arent Exceptions meant for exceptional conditions, not normal program flow?
    Otaku no Kamisama – God of the Geeks

  5. #5

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Re: Design issues, need advice.

    Ok, for the time being, I have commented out the sections related to checking to see if the appointment date is available.

    I am trying to atleast get it to work first then worry about checking for availibility.

    I am getting an error

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: Unable to compile class for JSP

    Generated servlet error:
    Syntax error, insert "}" to complete Block

    Generated servlet error:
    Syntax error on token "}", delete this token

    Generated servlet error:
    Syntax error, insert "}" to complete ClassBody


    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    business.ApptServlet.doGet(ApptServlet.java:64)
    business.ApptServlet.doPost(ApptServlet.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.


    --------------------------------------------------------------------------------
    The only part that I can recognize is
    business.ApptServlet.doGet(ApptServlet.java:64)
    business.ApptServlet.doPost(ApptServlet.java:70)
    So I went and looked at those two lines of my servlet and I cant see why I am getting an error with them.

    Line 64
    Code:
    dispatcher.forward(request, response);
    Line 70
    Code:
    doGet(request, response);
    I have included an updated version of my code in a ZIP file in this post.
    Otaku no Kamisama – God of the Geeks

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Design issues, need advice.

    in public void setAppointment(...) add this:
    Code:
    if(pl.isTaken(appt))
    {
    throw new ServletException("redirect to error");
    }
    Then Add throws ServletException to setAppointment(...) and to public PatientList(...)

    On doGet(...) in ApptServlet class add the following:
    Code:
    try {
            pl = new PatientList(strName, patID, reason, year
                                 , month, date, hour, minute) ;
          }
          catch (ServletException ex) {
            if (ex.getMessage().equals("redirect to error")) {
              getServletContext().getRequestDispatcher("/Error.jsp").include(
                  request, response) ;
            }
          }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  7. #7

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Re: Design issues, need advice.

    Not that that wont work, but am I supposed to be using exceptions that way?
    Otaku no Kamisama – God of the Geeks

  8. #8

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Re: Design issues, need advice.

    Now, it is printing out the Information that you enter in the Assign2.jsp. But what good is an appointment program if you cant enter more than one correct?

    Well, now I am trying to add sessions to my servlet and I am failing horribly it seems. It will still print out the information for the one person that you enter, but if you enter another patients information, it overwrites the previous one. I have been looking and cant find what I am doing wrong. I dont believe I am using sessions correctly. Any ideas?
    Otaku no Kamisama – God of the Geeks

  9. #9
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Design issues, need advice.

    If you really need help contact me on any IM on my public profile
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  10. #10

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Re: Design issues, need advice.

    Ok, I have gotten a little further on the session. I am having a problem with a null pointer exception. What stumps me is it occurs where I am adding an appointment to the list. Can you see what I am missing?

    Code:
    patientList.add(appt);
    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    java.lang.NullPointerException
    business.PatientList.setAppointments(PatientList.java:37)
    business.ApptServlet.doGet(ApptServlet.java:72)
    business.ApptServlet.doPost(ApptServlet.java:85)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

    Otaku no Kamisama – God of the Geeks

  11. #11

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Re: Design issues, need advice.

    Ok, I deleted the compiled JSP java files that Tomcat generates for me and deleted my .class files that I compiled and then stopped and started tomcat and now the session works. MAN!!!
    Otaku no Kamisama – God of the Geeks

Posting Permissions

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



Click Here to Expand Forum to Full Width