[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

bean not found within scope

Posted on 2007-04-03
27
Medium Priority
?
5,793 Views
Last Modified: 2013-11-24
I am getting error  bean newBean not found within scope. I have changed the scope from session to request, and the bean is imported to the jsp page.What could be causing this error?
0
Comment
Question by:Styx218
  • 17
  • 10
27 Comments
 
LVL 11

Expert Comment

by:Manish
ID: 18842518
Please post the jsp code.
0
 

Author Comment

by:Styx218
ID: 18842639
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>


<%@ page import="com.football.Team"%>

<jsp:useBean id = "newTeam" type = "com.football.Team" scope ="session"/>
<jsp:setProperty name = "newTeam" property = "name"  />


<import javax.servlet.http.HttpSession/>


<c:set value = "Admin Page " var = "title" />

<sql:query var = "example" dataSource = "jdbc:mysql://localhost/footydb,com.mysql.jdbc.Driver,footy,footy">
 SELECT * from teams
</sql:query>

<html>
  <head>
    <script type="text/javascript" >


<form action="AdminServlet" method="POST">
      
      <input type="hidden" name="ACTION" value="LIST_ADD" />
      <tr>
        <td colspan="2"><b>Add new Team</b></td>
        <td><input type = "text"  name="name"  size="20"  /></td>
        <td><input name="ADD" type="submit" value="Add" /></td>
        <td>&nbsp;</td>
      </tr>
      

  </table>
        
        
        
        
        
                    
<a href="menu.html">Main Menu</a>
 <a href="admin.jsp">Admin Home</a>
             </body>
             </html>
0
 
LVL 11

Expert Comment

by:Manish
ID: 18842828
>><%@ page import="com.football.Team"%>
No need to import.

<jsp:useBean id = "newTeam" type = "com.football.Team" scope ="session"/>
where are you adding this in request or session?

Is Team class in classpath?
Are you using any IDE?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Styx218
ID: 18842923
where are you adding this in request or session?

i dont understand.

Is Team class in classpath?
No, i have to add complete path to classpath? why is this?

I am using NetBeans 4.1

Thanks for your help :)

0
 
LVL 11

Expert Comment

by:Manish
ID: 18842943
<jsp:useBean id = "newTeam" class = "com.football.Team" scope ="session"/>

Is this give you error?

If you use type instead of class, this bean should be added in request or session , so that it will available in jsp.
0
 
LVL 11

Expert Comment

by:Manish
ID: 18843004
How you want to set values in Bean? where are you setting it?
0
 

Author Comment

by:Styx218
ID: 18843020
i was using type and still got same error
0
 

Author Comment

by:Styx218
ID: 18843041
Do you want my Bean code?
0
 
LVL 11

Expert Comment

by:Manish
ID: 18843073
If you type , the bean class should be availabe in request or session.
0
 
LVL 11

Expert Comment

by:Manish
ID: 18843075
>>If you type ,
If you use type
0
 
LVL 11

Expert Comment

by:Manish
ID: 18843084
Use class if you want to instantiate it like new in java.
0
 

Author Comment

by:Styx218
ID: 18843094
well i have tried both and am getting same error,  i think problem is to do with jsp:setProperty, do i have to have a corresponding jsp:getProperty??
0
 
LVL 11

Expert Comment

by:Manish
ID: 18843098
Post Bean code.
0
 
LVL 11

Expert Comment

by:Manish
ID: 18843106
0
 
LVL 11

Expert Comment

by:Manish
ID: 18843112
<jsp:useBean id="myBean2" class="com.mycompany.MyBean" scope="session">
        <%-- this body is executed only if the bean is created --%>
   
        <%-- intialize bean properties --%>
        <jsp:setProperty name="myBean2" property="prop1" value="123" />
    </jsp:useBean>
0
 

Author Comment

by:Styx218
ID: 18843113
package com.football;

import java.beans.*;
import java.io.Serializable;

public class Team  implements Serializable
{
    private int    id;
    private String name;

    public Team(String newTeam,int num)
    {
        id = id;
        name = name;
    }

    public int getId()
    {
        return id;
    }

    public String getName()
    {
        return name;
    }

    public boolean equals(Object obj)
    {
        if (obj instanceof Team)
        {
            Team compare = (Team)obj;
            return (id == compare.getId());
        }
        return false;
    }

    public int hashCode()
    {
        return name.hashCode();
    }

    public String toString()
    {
        return getClass() + "[" + id + "] : [" + name + "]";
    }



    private void setId(int id)
    {
        id = id;
    }

    private void setName(String name)
    {
        name = name;
    }
0
 
LVL 11

Expert Comment

by:Manish
ID: 18843131
public Team(String newTeam,int num)
    {
        id = id;
        name = name;
    }

dont pass parameter to constructor.
remove it.
0
 

Author Comment

by:Styx218
ID: 18843184
The problem with not passing parameter is this
 try

       {
                                           manager = getFootyManager();  //call method to get connection
               manager.addNewTeamToList(new Team(0, newTeam));

I pass instance of Bean to method addNewTeamToList
0
 

Author Comment

by:Styx218
ID: 18843194
*Which is expecting a string and an int as parameters in constructor
0
 
LVL 11

Expert Comment

by:Manish
ID: 18844019
 public Team(String newTeam,int num)
    {
        id = id;
        name = name;
    }
  public Team()
    {
        id = id;
        name = name;
    }
0
 
LVL 11

Expert Comment

by:Manish
ID: 18844026
sorry
  public Team(String newTeam,int num)
    {
        id = id;
        name = name;
    }
  public Team()
    {
       
    }
0
 
LVL 11

Expert Comment

by:Manish
ID: 18844069
0
 

Author Comment

by:Styx218
ID: 18844209
exception

javax.servlet.ServletException: bean newTeam not found within scope
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
      org.apache.jsp.index_jsp._jspService(index_jsp.java:195)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)


root cause

java.lang.InstantiationException: bean newTeam not found within scope
      org.apache.jsp.index_jsp._jspService(index_jsp.java:98)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)

0
 
LVL 11

Expert Comment

by:Manish
ID: 18848610
Are you using type in usebean tag?
0
 
LVL 11

Expert Comment

by:Manish
ID: 18848615
what is flow of you application?
0
 

Author Comment

by:Styx218
ID: 18857102
As above

<jsp:useBean id = "newTeam" type = "com.football.Team" scope ="session"/>
<jsp:setProperty name = "newTeam" property = "name"  />


The flow of my application is as follows

index.jsp provides a form to add users to database.Name is typed into form and "Add" button is pressed. Parameter should be passed to servlet within bean. Servlet  processes request and passes parameter to method within another class containing sql command. index.jsp should then be refereshed, displaying added information from database
0
 
LVL 11

Accepted Solution

by:
Manish earned 500 total points
ID: 18862546
If you are using type in jsp in useBean tag.
You should add bean in session or request before coming to this jsp.
request.setAttribute("bean",new Team());
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
A solution for Fortify Path Manipulation.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month17 days, 21 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question