Bean problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nvidia1
    New Member
    • Mar 2007
    • 2

    Bean problem

    Hi this is my first post but so far this is pretty good site. I have a file called index.html with the following code:

    Code:
    <!--  index.html  -->
    
    <html>
    <head><title>Student Registration Front</title></head>
    <body bgcolor="#ffffcc">
    
      <h2 align="center"><font color="#800000">Student Registration Webapp 2007</font></h2>
      
      <p>&nbsp;</p>
      <p>&nbsp;</p>
    
      <!-- <form action="http://localhost:8080/eventRegister/front.jsp" method="post"> -->
       <form action="https://tomcat.cscs.wmin.ac.uk:9191/tomcat/w1009048/front.jsp" method="post">
       <table align="center">
           <tr><th>Student Registration: </th>
               <td><input type="radio" name="choice" value="register" checked> </td>
               <td> <font color="blue">you must register here first</font></td></tr>
    			
           <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
           <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    		
           <tr><th>Login for registered students: </th>
               <td><input type="radio" name="choice" value="login"> </td>
               <td><font color="red">this is not yet implemented<br />
                                     and leads to a blank page</font></td></tr>
    			 
           <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    		
           <tr><td>&nbsp;</td>
               <th><input type="submit" value="Submit"></th>
               <td>&nbsp;</td></tr>
      	</table>
      </form>
    
    </body>
    </html>
    When they click on submit it goes to my front.jsp which has the following code(front.jsp is actually FrontController .java changed in web.xml):

    Code:
    //  FrontController.java
    
    import java.io.* ;
    import java.util.* ;
    import javax.servlet.* ;
    import javax.servlet.http.* ;
    import beans.*;
    
    /* 
       The front controller:
       * creates a new 'session' object,
       * creates an empty 'error message' String which it stores in 'session', then
       * redirects the request to either: 
           - 'register' (the real JSP, register.jsp),  or 
           - 'login' (not implemented) 
    */
    
    public class FrontController extends HttpServlet
    {
       public void doPost( HttpServletRequest request, HttpServletResponse response )
                      throws IOException, ServletException
       {
          String strChoice = request.getParameter( "choice" );
       	
          if ( strChoice.equals( "register" ) )
          {
             HttpSession session = request.getSession();
    	  	
             String strError = " ";  /*  now 'store' this String object - this is not a bean
                                         but can be stored in 'session' in exactly the same way */
             session.setAttribute( "error", strError );  
    	  	
             RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( "/register.jsp" );
             dispatcher.forward( request, response );
          }
          else
          {
             RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( "/login.jsp" );
             dispatcher.forward( request, response );
          }
       }
    }
    After from frontcontroller , it should go into register.jsp but it does not becuase it i get this error message:

    Code:
    HTTP Status 500 - 
    
    --------------------------------------------------------------------------------
    
    type Exception report
    
    message 
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception 
    
    org.apache.jasper.JasperException: /register.jsp(4,0) The value for the useBean class attribute bean.Counter is invalid.
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    	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)
    	FrontController.doPost(FrontController.java:34)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    
    
    root cause 
    
    org.apache.jasper.JasperException: /register.jsp(4,0) The value for the useBean class attribute bean.Counter is invalid.
    	org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
    	org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
    	org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
    	org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
    	org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
    	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    	org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
    	org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
    	org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
    	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    	org.apache.jasper.compiler.Generator.generate(Generator.java:3320)
    	org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
    	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
    	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)
    	FrontController.doPost(FrontController.java:34)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    The reason why it shows this error message is cos i add this following line of code in my register.jsp: <jsp:useBean id="counterid" class="bean.Cou nter" scope="applicat ion" />
    The full code is here:

    Code:
    <%--  register.jsp  --%>
    
    <%@ page language="java" contentType="text/html; charset-ISO-8859-1" %> 
    <jsp:useBean id="counterid" class="bean.Counter" scope="application" />
    
    <html>
    <head><title>Student Registration Front</title></head>
    <body bgcolor="#ffffcc">
      <h2 align="center"><font color="#800000">Student Registration Webapp 2007</font></h2>
      
      <h3 align="center"><font color="red"><i> 
          <% String e = (String) session.getAttribute( "error" );
             out.print( e ); %> 
      </i></font></h3>
       
      
    
      <form action="registerStudent.jsp" method="post">
        <table align="center">
            <tr><th>Enter Surname: </th>
                <td><input type="text" name="surname" size="20"></td></tr>
            <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
            <tr><th>Enter First Names: </th>
                <td><input type="text" name="firstname" size="20"></td></tr>
            <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
            <tr><th>Enter 8 Registration Digits: </th>
                <td><input type="text" name="reg" size="8"></td></tr>
            <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
            <tr><th>Enter Module: </th>
                <td><select name="module">
                      <option value="3sfe513">3sfe513
                      <option value="3sfe7a6">3sfe7a6
                   </select>
                </td></tr>
            <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
            <tr><th>Enter Password for Webapp Login: </th>
                <td><input type="password" name="password" value="" size="8"></td></tr>
            <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
            <tr><th colspan="2"><input type="submit" value="Submit"></th></tr>
         </table>
        </form>
    
    </body>
    </html>
    The register.jsp is used to allow member to enter their details and once they are submitted the data will be stored in mysql db. Now, can somone tell me why when i add the following code i get the following error message. If i dont add the following code, after i submit the first page it goes to my register.jsp. Please help if you cannn, please help..
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by nvidia1
    Hi this is my first post but so far this is pretty good site. I have a file called index.html with the following code:

    Code:
    <!-- index.html -->
     
    <html>
    <head><title>Student Registration Front</title></head>
    <body bgcolor="#ffffcc">
     
    <h2 align="center"><font color="#800000">Student Registration Webapp 2007</font></h2>
     
    <p>&nbsp;</p>
    <p>&nbsp;</p>
     
    <!-- <form action="http://localhost:8080/eventRegister/front.jsp" method="post"> -->
    <form action="https://tomcat.cscs.wmin.ac.uk:9191/tomcat/w1009048/front.jsp" method="post">
    <table align="center">
    <tr><th>Student Registration: </th>
    <td><input type="radio" name="choice" value="register" checked> </td>
    <td> <font color="blue">you must register here first</font></td></tr>
     
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
     
    <tr><th>Login for registered students: </th>
    <td><input type="radio" name="choice" value="login"> </td>
    <td><font color="red">this is not yet implemented<br />
    and leads to a blank page</font></td></tr>
     
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
     
    <tr><td>&nbsp;</td>
    <th><input type="submit" value="Submit"></th>
    <td>&nbsp;</td></tr>
    	</table>
    </form>
     
    </body>
    </html>
    When they click on submit it goes to my front.jsp which has the following code(front.jsp is actually FrontController .java changed in web.xml):

    Code:
    // FrontController.java
     
    import java.io.* ;
    import java.util.* ;
    import javax.servlet.* ;
    import javax.servlet.http.* ;
    import beans.*;
     
    /* 
    The front controller:
    * creates a new 'session' object,
    * creates an empty 'error message' String which it stores in 'session', then
    * redirects the request to either: 
    - 'register' (the real JSP, register.jsp), or 
    - 'login' (not implemented) 
    */
     
    public class FrontController extends HttpServlet
    {
    public void doPost( HttpServletRequest request, HttpServletResponse response )
    throws IOException, ServletException
    {
    String strChoice = request.getParameter( "choice" );
     
    if ( strChoice.equals( "register" ) )
    {
    HttpSession session = request.getSession();
     
    String strError = " "; /* now 'store' this String object - this is not a bean
    but can be stored in 'session' in exactly the same way */
    session.setAttribute( "error", strError ); 
     
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( "/register.jsp" );
    dispatcher.forward( request, response );
    }
    else
    {
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( "/login.jsp" );
    dispatcher.forward( request, response );
    }
    }
    }
    After from frontcontroller , it should go into register.jsp but it does not becuase it i get this error message:

    Code:
     
    HTTP Status 500 - 
     
    --------------------------------------------------------------------------------
     
    type Exception report
     
    message 
     
    description The server encountered an internal error () that prevented it from fulfilling this request.
     
    exception 
     
    org.apache.jasper.JasperException: /register.jsp(4,0) The value for the useBean class attribute bean.Counter is invalid.
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    	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)
    	FrontController.doPost(FrontController.java:34)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
     
     
    root cause 
     
    org.apache.jasper.JasperException: /register.jsp(4,0) The value for the useBean class attribute bean.Counter is invalid.
    	org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
    	org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
    	org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
    	org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
    	org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
    	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    	org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
    	org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
    	org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
    	org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    	org.apache.jasper.compiler.Generator.generate(Generator.java:3320)
    	org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
    	org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
    	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
    	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)
    	FrontController.doPost(FrontController.java:34)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    The reason why it shows this error message is cos i add this following line of code in my register.jsp: <jsp:useBean id="counterid" class="bean.Cou nter" scope="applicat ion" />
    The full code is here:

    Code:
    <%-- register.jsp --%>
     
    <%@ page language="java" contentType="text/html; charset-ISO-8859-1" %> 
    <jsp:useBean id="counterid" class="bean.Counter" scope="application" />
     
    <html>
    <head><title>Student Registration Front</title></head>
    <body bgcolor="#ffffcc">
    <h2 align="center"><font color="#800000">Student Registration Webapp 2007</font></h2>
     
    <h3 align="center"><font color="red"><i> 
    <% String e = (String) session.getAttribute( "error" );
    out.print( e ); %> 
    </i></font></h3>
     
     
     
    <form action="registerStudent.jsp" method="post">
    <table align="center">
    <tr><th>Enter Surname: </th>
    <td><input type="text" name="surname" size="20"></td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><th>Enter First Names: </th>
    <td><input type="text" name="firstname" size="20"></td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><th>Enter 8 Registration Digits: </th>
    <td><input type="text" name="reg" size="8"></td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><th>Enter Module: </th>
    <td><select name="module">
    <option value="3sfe513">3sfe513
    <option value="3sfe7a6">3sfe7a6
    </select>
    </td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><th>Enter Password for Webapp Login: </th>
    <td><input type="password" name="password" value="" size="8"></td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><th colspan="2"><input type="submit" value="Submit"></th></tr>
    </table>
    </form>
     
    </body>
    </html>
    The register.jsp is used to allow member to enter their details and once they are submitted the data will be stored in mysql db. Now, can somone tell me why when i add the following code i get the following error message. If i dont add the following code, after i submit the first page it goes to my register.jsp. Please help if you cannn, please help..
    It is bean.Counter or is it supposed to be beans.Counter or possibly just Counter?

    Comment

    • nvidia1
      New Member
      • Mar 2007
      • 2

      #3
      Originally posted by r035198x
      It is bean.Counter or is it supposed to be beans.Counter or possibly just Counter?

      Ahhhhh, it is meant to be beans.Counter. I looked at my folder name. I don't know about you but sometimes when programming in general you don't always see your own mistakes, therefore it is always good to ask somebody else as they might have a different view. Thanks for you'r help and sorry if i have caused any inconvience.

      Comment

      Working...