By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,602 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

Bean problem

P: 2
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:

Expand|Select|Wrap|Line Numbers
  1. <!--  index.html  -->
  2.  
  3. <html>
  4. <head><title>Student Registration Front</title></head>
  5. <body bgcolor="#ffffcc">
  6.  
  7.   <h2 align="center"><font color="#800000">Student Registration Webapp 2007</font></h2>
  8.  
  9.   <p>&nbsp;</p>
  10.   <p>&nbsp;</p>
  11.  
  12.   <!-- <form action="http://localhost:8080/eventRegister/front.jsp" method="post"> -->
  13.    <form action="https://tomcat.cscs.wmin.ac.uk:9191/tomcat/w1009048/front.jsp" method="post">
  14.    <table align="center">
  15.        <tr><th>Student Registration: </th>
  16.            <td><input type="radio" name="choice" value="register" checked> </td>
  17.            <td> <font color="blue">you must register here first</font></td></tr>
  18.  
  19.        <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  20.        <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  21.  
  22.        <tr><th>Login for registered students: </th>
  23.            <td><input type="radio" name="choice" value="login"> </td>
  24.            <td><font color="red">this is not yet implemented<br />
  25.                                  and leads to a blank page</font></td></tr>
  26.  
  27.        <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  28.  
  29.        <tr><td>&nbsp;</td>
  30.            <th><input type="submit" value="Submit"></th>
  31.            <td>&nbsp;</td></tr>
  32.       </table>
  33.   </form>
  34.  
  35. </body>
  36. </html>
  37.  
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):

Expand|Select|Wrap|Line Numbers
  1. //  FrontController.java
  2.  
  3. import java.io.* ;
  4. import java.util.* ;
  5. import javax.servlet.* ;
  6. import javax.servlet.http.* ;
  7. import beans.*;
  8.  
  9. /* 
  10.    The front controller:
  11.    * creates a new 'session' object,
  12.    * creates an empty 'error message' String which it stores in 'session', then
  13.    * redirects the request to either: 
  14.        - 'register' (the real JSP, register.jsp),  or 
  15.        - 'login' (not implemented) 
  16. */
  17.  
  18. public class FrontController extends HttpServlet
  19. {
  20.    public void doPost( HttpServletRequest request, HttpServletResponse response )
  21.                   throws IOException, ServletException
  22.    {
  23.       String strChoice = request.getParameter( "choice" );
  24.  
  25.       if ( strChoice.equals( "register" ) )
  26.       {
  27.          HttpSession session = request.getSession();
  28.  
  29.          String strError = " ";  /*  now 'store' this String object - this is not a bean
  30.                                      but can be stored in 'session' in exactly the same way */
  31.          session.setAttribute( "error", strError );  
  32.  
  33.          RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( "/register.jsp" );
  34.          dispatcher.forward( request, response );
  35.       }
  36.       else
  37.       {
  38.          RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( "/login.jsp" );
  39.          dispatcher.forward( request, response );
  40.       }
  41.    }
  42. }
  43.  
After from frontcontroller, it should go into register.jsp but it does not becuase it i get this error message:

Expand|Select|Wrap|Line Numbers
  1.  
  2. HTTP Status 500 - 
  3.  
  4. --------------------------------------------------------------------------------
  5.  
  6. type Exception report
  7.  
  8. message 
  9.  
  10. description The server encountered an internal error () that prevented it from fulfilling this request.
  11.  
  12. exception 
  13.  
  14. org.apache.jasper.JasperException: /register.jsp(4,0) The value for the useBean class attribute bean.Counter is invalid.
  15.     org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
  16.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
  17.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  18.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  19.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  20.     FrontController.doPost(FrontController.java:34)
  21.     javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
  22.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  23.  
  24.  
  25. root cause 
  26.  
  27. org.apache.jasper.JasperException: /register.jsp(4,0) The value for the useBean class attribute bean.Counter is invalid.
  28.     org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
  29.     org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
  30.     org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
  31.     org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
  32.     org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
  33.     org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
  34.     org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
  35.     org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
  36.     org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
  37.     org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
  38.     org.apache.jasper.compiler.Generator.generate(Generator.java:3320)
  39.     org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
  40.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
  41.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
  42.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
  43.     org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
  44.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
  45.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  46.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  47.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  48.     FrontController.doPost(FrontController.java:34)
  49.     javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
  50.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  51.  
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.Counter" scope="application" />
The full code is here:

Expand|Select|Wrap|Line Numbers
  1. <%--  register.jsp  --%>
  2.  
  3. <%@ page language="java" contentType="text/html; charset-ISO-8859-1" %> 
  4. <jsp:useBean id="counterid" class="bean.Counter" scope="application" />
  5.  
  6. <html>
  7. <head><title>Student Registration Front</title></head>
  8. <body bgcolor="#ffffcc">
  9.   <h2 align="center"><font color="#800000">Student Registration Webapp 2007</font></h2>
  10.  
  11.   <h3 align="center"><font color="red"><i> 
  12.       <% String e = (String) session.getAttribute( "error" );
  13.          out.print( e ); %> 
  14.   </i></font></h3>
  15.  
  16.  
  17.  
  18.   <form action="registerStudent.jsp" method="post">
  19.     <table align="center">
  20.         <tr><th>Enter Surname: </th>
  21.             <td><input type="text" name="surname" size="20"></td></tr>
  22.         <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  23.         <tr><th>Enter First Names: </th>
  24.             <td><input type="text" name="firstname" size="20"></td></tr>
  25.         <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  26.         <tr><th>Enter 8 Registration Digits: </th>
  27.             <td><input type="text" name="reg" size="8"></td></tr>
  28.         <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  29.         <tr><th>Enter Module: </th>
  30.             <td><select name="module">
  31.                   <option value="3sfe513">3sfe513
  32.                   <option value="3sfe7a6">3sfe7a6
  33.                </select>
  34.             </td></tr>
  35.         <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  36.         <tr><th>Enter Password for Webapp Login: </th>
  37.             <td><input type="password" name="password" value="" size="8"></td></tr>
  38.         <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  39.         <tr><th colspan="2"><input type="submit" value="Submit"></th></tr>
  40.      </table>
  41.     </form>
  42.  
  43. </body>
  44. </html>
  45.  
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..
Mar 30 '07 #1
Share this Question
Share on Google+
2 Replies


10K+
P: 13,264
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:

Expand|Select|Wrap|Line Numbers
  1. <!-- index.html -->
  2.  
  3. <html>
  4. <head><title>Student Registration Front</title></head>
  5. <body bgcolor="#ffffcc">
  6.  
  7. <h2 align="center"><font color="#800000">Student Registration Webapp 2007</font></h2>
  8.  
  9. <p>&nbsp;</p>
  10. <p>&nbsp;</p>
  11.  
  12. <!-- <form action="http://localhost:8080/eventRegister/front.jsp" method="post"> -->
  13. <form action="https://tomcat.cscs.wmin.ac.uk:9191/tomcat/w1009048/front.jsp" method="post">
  14. <table align="center">
  15. <tr><th>Student Registration: </th>
  16. <td><input type="radio" name="choice" value="register" checked> </td>
  17. <td> <font color="blue">you must register here first</font></td></tr>
  18.  
  19. <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  20. <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  21.  
  22. <tr><th>Login for registered students: </th>
  23. <td><input type="radio" name="choice" value="login"> </td>
  24. <td><font color="red">this is not yet implemented<br />
  25. and leads to a blank page</font></td></tr>
  26.  
  27. <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  28.  
  29. <tr><td>&nbsp;</td>
  30. <th><input type="submit" value="Submit"></th>
  31. <td>&nbsp;</td></tr>
  32.     </table>
  33. </form>
  34.  
  35. </body>
  36. </html>
  37.  
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):

Expand|Select|Wrap|Line Numbers
  1. // FrontController.java
  2.  
  3. import java.io.* ;
  4. import java.util.* ;
  5. import javax.servlet.* ;
  6. import javax.servlet.http.* ;
  7. import beans.*;
  8.  
  9. /* 
  10. The front controller:
  11. * creates a new 'session' object,
  12. * creates an empty 'error message' String which it stores in 'session', then
  13. * redirects the request to either: 
  14. - 'register' (the real JSP, register.jsp), or 
  15. - 'login' (not implemented) 
  16. */
  17.  
  18. public class FrontController extends HttpServlet
  19. {
  20. public void doPost( HttpServletRequest request, HttpServletResponse response )
  21. throws IOException, ServletException
  22. {
  23. String strChoice = request.getParameter( "choice" );
  24.  
  25. if ( strChoice.equals( "register" ) )
  26. {
  27. HttpSession session = request.getSession();
  28.  
  29. String strError = " "; /* now 'store' this String object - this is not a bean
  30. but can be stored in 'session' in exactly the same way */
  31. session.setAttribute( "error", strError ); 
  32.  
  33. RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( "/register.jsp" );
  34. dispatcher.forward( request, response );
  35. }
  36. else
  37. {
  38. RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( "/login.jsp" );
  39. dispatcher.forward( request, response );
  40. }
  41. }
  42. }
  43.  
After from frontcontroller, it should go into register.jsp but it does not becuase it i get this error message:

Expand|Select|Wrap|Line Numbers
  1.  
  2. HTTP Status 500 - 
  3.  
  4. --------------------------------------------------------------------------------
  5.  
  6. type Exception report
  7.  
  8. message 
  9.  
  10. description The server encountered an internal error () that prevented it from fulfilling this request.
  11.  
  12. exception 
  13.  
  14. org.apache.jasper.JasperException: /register.jsp(4,0) The value for the useBean class attribute bean.Counter is invalid.
  15.     org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
  16.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
  17.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  18.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  19.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  20.     FrontController.doPost(FrontController.java:34)
  21.     javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
  22.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  23.  
  24.  
  25. root cause 
  26.  
  27. org.apache.jasper.JasperException: /register.jsp(4,0) The value for the useBean class attribute bean.Counter is invalid.
  28.     org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
  29.     org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
  30.     org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
  31.     org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
  32.     org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
  33.     org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
  34.     org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
  35.     org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
  36.     org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
  37.     org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
  38.     org.apache.jasper.compiler.Generator.generate(Generator.java:3320)
  39.     org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
  40.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
  41.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
  42.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
  43.     org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
  44.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
  45.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  46.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  47.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  48.     FrontController.doPost(FrontController.java:34)
  49.     javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
  50.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  51.  
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.Counter" scope="application" />
The full code is here:

Expand|Select|Wrap|Line Numbers
  1. <%-- register.jsp --%>
  2.  
  3. <%@ page language="java" contentType="text/html; charset-ISO-8859-1" %> 
  4. <jsp:useBean id="counterid" class="bean.Counter" scope="application" />
  5.  
  6. <html>
  7. <head><title>Student Registration Front</title></head>
  8. <body bgcolor="#ffffcc">
  9. <h2 align="center"><font color="#800000">Student Registration Webapp 2007</font></h2>
  10.  
  11. <h3 align="center"><font color="red"><i> 
  12. <% String e = (String) session.getAttribute( "error" );
  13. out.print( e ); %> 
  14. </i></font></h3>
  15.  
  16.  
  17.  
  18. <form action="registerStudent.jsp" method="post">
  19. <table align="center">
  20. <tr><th>Enter Surname: </th>
  21. <td><input type="text" name="surname" size="20"></td></tr>
  22. <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  23. <tr><th>Enter First Names: </th>
  24. <td><input type="text" name="firstname" size="20"></td></tr>
  25. <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  26. <tr><th>Enter 8 Registration Digits: </th>
  27. <td><input type="text" name="reg" size="8"></td></tr>
  28. <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  29. <tr><th>Enter Module: </th>
  30. <td><select name="module">
  31. <option value="3sfe513">3sfe513
  32. <option value="3sfe7a6">3sfe7a6
  33. </select>
  34. </td></tr>
  35. <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  36. <tr><th>Enter Password for Webapp Login: </th>
  37. <td><input type="password" name="password" value="" size="8"></td></tr>
  38. <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  39. <tr><th colspan="2"><input type="submit" value="Submit"></th></tr>
  40. </table>
  41. </form>
  42.  
  43. </body>
  44. </html>
  45.  
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?
Mar 31 '07 #2

P: 2
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.
Mar 31 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.