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

Java bean in JSP

P: 17
HTML PAGE
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <form action="second.jsp" method="get">
  4. YOur name <input type=text name="name">
  5. <input type=submit > 
  6. </form>
  7. </body>
  8. </html>
  9.  
// taking input from this and passing it to second.jsp
Expand|Select|Wrap|Line Numbers
  1. <jsp:useBean id="user" class="user.userclass" scope="session"/> 
  2. <jsp:setProperty name="user" property="name"/>             //setting name 
  3. <html>
  4. <body>
  5. <a href="third.jsp"> continue </a> 
  6. </body>
  7. </html>
  8.  
// seting name into bean file "userclass"


//getting name from bean file "userclass"
Expand|Select|Wrap|Line Numbers
  1. <jsp:userBean id="user" class="user.userclass" scope="session"/>
  2. <html>
  3. <body>
  4. <h1> your details 
  5. your name:<%= user.getUsername() %>
  6. </body>
  7. </html>
  8.  


when i run the above program , it is unable to find bean file ,

error is :
org.apache.jasper.JasperException: /second.jsp(2,0) The value for the useBean class attribute user.userclass is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jsp Error(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatc h(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspErro r(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisit or.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Nod e.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.j ava: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.j ava:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.j ava:2163)
org.apache.jasper.compiler.Generator.generate(Gene rator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(C ompiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:470)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:451)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:439)
org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)


am i missing something , i want to know where to place .class file(bean file)
Feb 11 '08 #1
Share this Question
Share on Google+
1 Reply


P: 49
HTML PAGE
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <form action="second.jsp" method="get">
  4. YOur name <input type=text name="name">
  5. <input type=submit > 
  6. </form>
  7. </body>
  8. </html>
  9.  
// taking input from this and passing it to second.jsp
Expand|Select|Wrap|Line Numbers
  1. <jsp:useBean id="user" class="user.userclass" scope="session"/> 
  2. <jsp:setProperty name="user" property="name"/>             //setting name 
  3. <html>
  4. <body>
  5. <a href="third.jsp"> continue </a> 
  6. </body>
  7. </html>
  8.  
// seting name into bean file "userclass"


//getting name from bean file "userclass"
Expand|Select|Wrap|Line Numbers
  1. <jsp:userBean id="user" class="user.userclass" scope="session"/>
  2. <html>
  3. <body>
  4. <h1> your details 
  5. your name:<%= user.getUsername() %>
  6. </body>
  7. </html>
  8.  


when i run the above program , it is unable to find bean file ,

error is :
org.apache.jasper.JasperException: /second.jsp(2,0) The value for the useBean class attribute user.userclass is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jsp Error(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatc h(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspErro r(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisit or.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Nod e.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.j ava: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.j ava:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.j ava:2163)
org.apache.jasper.compiler.Generator.generate(Gene rator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(C ompiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:470)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:451)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:439)
org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)


am i missing something , i want to know where to place .class file(bean file)
is your class file in the same package or in a different location?????

If the <jsp:use-Bean> action cannot find an existing bean in the specified scope, it creates a new instance of the beanís class as specified by the value of the class attribute using the classís publicly defined no-argument constructor. Therefore, the class specified by the class attribute must be a public non-abstract class and must have a public no-argument
constructor. If the class is part of a package, then the fully qualified class
name must be specified as mypackage.MyClass.
Feb 11 '08 #2

Post your reply

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