Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getProperty of a java bean  RSS feed

 
April Benzine
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>
 
Sanjeev Kaushik
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".
 
M. Gagnon
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!