• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

getProperty of a java bean

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to access a bean's property from a jsp. A servlet is used in the middle. when I try the getProperty I get this error and I don't know what it means:

Note: sun.tools.javac.Main has been deprecated.
c:\ServletExec\Servlets\pagecompile\_projFourJSP_xjsp.java:42: Variable 'bean' is already defined in this method.
Object bean = pageContext.findAttribute( "bean" );
^
1 error, 1 warning

Please help

Code for JSP:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<title>Project Four JSP</title>
<jsp:useBean id="bean"
class="java146.project4.ProjectFourServlet"
scope="application"/>
</head>
<body bgcolor = silver>
<center><h1>Search Results For Project Four</h1></center>
<table border = 2>
<th>
<tr>
<td>Empoyee ID </td>
<td>First Name </td>
<td>Middle Name </td>
<td>Last Name </td>
<td>SSN </td>
<td>Department </td>
<td>Room</td>
<td>Phone Ex.</td>
</tr>
</th>
<I><jsp:getProperty name="bean" property="employeeTable" /></I>
</table>



<A HREF="/">Home</A>
</body>
</html>
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Defining, creating, accessing a bean, all these statements will become a part of jspService method.
In one method you can define only one variable with a particular name. If you use the already defined variable, it will fail to compile.

From your JSP it appears that if this JSP is statically included in some another time at the time of compilation, and "bean" variable is also used there, then this error can come.

In static inclusion, contents of included JSP and including JSP will come in one translation unit.

Just check your code, if such scenario is occuring. Or try change the variable name e.g. "bean" to "employeeBean".
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Sanjeev is right. Do you have an import statement in the example you've posted here that we're not seeing?

<%@ include file="SomeOtherPage.jsp" %>

If so, that file must also have the same <useBean> tag in it.
 
April Benzine
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for helping
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic