aspose file tools*
The moose likes JSP and the fly likes jsp usebean action tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp usebean action tag" Watch "jsp usebean action tag" New topic
Author

jsp usebean action tag

zalak thakkar
Ranch Hand

Joined: Sep 09, 2013
Posts: 33
Hello everyone...

I m trying to run 1 jsp program using action tag <jsp:usebean> and got following errors can any one just tell me what is this?

cannot find symbol
symbol : class studentsbean
location: class org.apache.jsp.beandemo_jsp
studentsbean student = null;
D:\ZALAK\NIIT_students\AdvancedJava_Programs\DemoUseBean\build\generated\src\org\apache\jsp\beandemo_jsp.java:55: cannot find symbol
symbol : class studentsbean
location: class org.apache.jsp.beandemo_jsp
student = (studentsbean) _jspx_page_context.getAttribute("student", PageContext.PAGE_SCOPE);
D:\ZALAK\NIIT_students\AdvancedJava_Programs\DemoUseBean\build\generated\src\org\apache\jsp\beandemo_jsp.java:57: cannot find symbol
symbol : class studentsbean
location: class org.apache.jsp.beandemo_jsp
student = new studentsbean();
D:\ZALAK\NIIT_students\AdvancedJava_Programs\DemoUseBean\build\generated\src\org\apache\jsp\beandemo_jsp.java:75: cannot find symbol
symbol : class studentsbean
location: class org.apache.jsp.beandemo_jsp
out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((studentsbean)_jspx_page_context.findAttribute("student")).getName())));
D:\ZALAK\NIIT_students\AdvancedJava_Programs\DemoUseBean\build\generated\src\org\apache\jsp\beandemo_jsp.java:81: cannot find symbol
symbol : class studentsbean
location: class org.apache.jsp.beandemo_jsp
out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((studentsbean)_jspx_page_context.findAttribute("student")).getAge())));
5 errors
D:\ZALAK\NIIT_students\AdvancedJava_Programs\DemoUseBean\nbproject\build-impl.xml:483: The following error occurred while executing this line:
D:\ZALAK\NIIT_students\AdvancedJava_Programs\DemoUseBean\nbproject\build-impl.xml:231: Compile failed; see the compiler error output for details.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Looks like the studentsbean Java Bean cannot be found, have you declared that class? Show us your JSP code (only the useBean declaration) and the studentsbean class. Also you have to reference the bean with its package, like:



By the way, normally classes are named camel case, in this case: public class StudentsBean.
zalak thakkar
Ranch Hand

Joined: Sep 09, 2013
Posts: 33
ok... my studentsbean.java class is like as below::



public class studentsbean
{
private String name = null;
private String email = null;
private int age = 0;

public String getName()
{
return name;
}
public String getEmail()
{
return email;
}
public int getAge()
{
return age;
}
public void setName(String name)
{
this.name = name;
}
public void setEmail(String email)
{
this.email = email;
}
public void setAge(int age)
{
this.age = age;
}
}
zalak thakkar
Ranch Hand

Joined: Sep 09, 2013
Posts: 33
And my jsp page is as below::

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>BeanData.jsp</title>
</head>
<body>
<jsp:useBean id="student" class="studentsbean">
<jsp:setProperty name="student" property="name" />
<jsp:setProperty name="student" property="email" />
<jsp:setProperty name="student" property="age"/>
</jsp:useBean>
<h1> <u> STUDENT DATA : </u> </h1>
<p> Name : <i><jsp:getProperty name="student" property="name"/></i> </p>
<p> Email-ID : <i><%= student.getEmail() %></i> </p>
<p> Age : <i><jsp:getProperty name="student" property="age"/></i> </p>
</body>
</html>



Please help me....
zalak thakkar
Ranch Hand

Joined: Sep 09, 2013
Posts: 33
ya Albareto, it could not find my studentsbean class...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

That's because you forgot to mention what package your studentsbean class was in. Look at Albareto's post again to see how to do that.

If you didn't put it in a package, that's a problem. Put it in a package.

(Also, while we're talking about naming conventions, if a bean is supposed to contain data about one student then "StudentsBean" is misleading. That leads me to believe that it contains information about students. A better name for a bean about one student would be "StudentBean".)
zalak thakkar
Ranch Hand

Joined: Sep 09, 2013
Posts: 33
yes i have read that comment by Albareto, but my java class is in default package and it has no name..
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Put it in a package and reference from the useBean with the complete package path as Paul suggested.

Edit, check this link, it is mandatory to have the Class in a package. It looks very much like your problem.
zalak thakkar
Ranch Hand

Joined: Sep 09, 2013
Posts: 33
Yeah,,it's working....Thank you so much - Albareto and Paul...:-)
 
Don't get me started about those stupid light bulbs.
 
subject: jsp usebean action tag