wood burning stoves 2.0*
The moose likes JSP and the fly likes bean error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "bean error" Watch "bean error" New topic
Author

bean error

Sanjay Izardar
Greenhorn

Joined: Apr 18, 2011
Posts: 19
i have made a file SimpleBean.java and use package statement package jspBook.ch3; in that.
then made a file hello.jsp and use the class file in hello.jsp
while running this file from browser i'm getting this error.


org.apache.jasper.JasperException: /ch3/hello.jsp(15,0) The value for the useBean class attribute jspBook.ch3.SimpleBean is invalid.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3833

You need to give more details here. Can you show us the JSP code fragment which uses the tag? And do you have the class file in the appropriate directory correspond to the package hierarchy inside the WEB-INF/classes directory?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Sanjay Izardar
Greenhorn

Joined: Apr 18, 2011
Posts: 19
hello.jsp


<!-- JSP Directives -->
<%@ page
errorPage="myError.jsp?from=hello.jsp"
%>

<html>
<head>
<title>Hello</title>
</head>

<body>
<basefont face="Arial">

<jsp:useBean id="SimpleBean" scope="session"

class="jspBook.ch3.SimpleBean"/>

<!-- Set bean properties -->
<jsp:setProperty name="SimpleBean" property="fname" value="Andrew"/>
<jsp:setProperty name="SimpleBean" property="lname" value="Patzer"/>

<!-- Display welcome message -->
<center>
<b><%= SimpleBean.welcomeMsg() %></b>
</center>
</body>
</html >
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
Hi Sanjay,Welcome to JavaRanch..........

Taking into consideration that you have put your JSP in ch3 folder in parallel of WEB-INF folder of your application,ensure these things-

1.Your Bean class is lying in package as you have specified in your bean class and JSP-
WEB-INF/classes/jspBook/ch3/SimpleBean.java

2.Names in your package hierarchy are matching exactly what they are,for example jspBook should not be Jspbook or JSPBook.

3.Your bean class has a public default constructor.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

You are wrong. The JSPs can be placed anywhere within the web app -- even under WEB-INF if they are to be hidden.

The most likely cause of the problem is a missing class file.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
Thanks Bear,
I was not aware of that.
Why we actually want to make our JSPs hidden?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3833

Ankit Tripathi wrote:1.Your Bean class is lying in package as you have specified in your bean class and JSP-
WEB-INF/classes/jspBook/ch3/SimpleBean.java

Note that the source files should not be put inside the classes folder in the web application but the class files.

Why we actually want to make our JSPs hidden?

You can make them not accessible directly by the clients and allow those pages to be rendered only by the application code.
Sanjay Izardar
Greenhorn

Joined: Apr 18, 2011
Posts: 19
even then it is not running.
I am confused, where to put class files and jsp files for javabeans.
suppose i have two files
1)index.jsp (placed in webapps\project)
2)MessageBean.class(placed in webapps\project\WEB-INF\classes)

index.jsp
<%@ page import="beans.MessageBean" %>
<HTML>
<HEAD>
<TITLE>Using a JavaBean</TITLE>
</HEAD>
<BODY>
<h1>Using a JavaBean</h1>

<% MessageBean m = new MessageBean(); %>

The message is: <%= m.msg() %>

</BODY>
</HTML>


MessageBean.java
package beans;


public class MessageBean
{
public MessageBean()
{
}

public String msg()
{
return "Hello from JSP!";
}
}


can anybody tell me the solution, please.

Deepakkumar Devarajan
Ranch Hand

Joined: Apr 19, 2011
Posts: 54

@Sanjay Did you placed MessageBean.class in webapps\project\WEB-INF\classes or in webapps\project\WEB-INF\classes\bean\? If you have placed it directly under classes folder then you cannot access it in your JSP. Your jsp page is in the right place. Please make sure class files are in the right path.


Regards,
Deepakkumar Devarajan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

2)MessageBean.class(placed in webapps\project\WEB-INF\classes)

You've already been told that this is wrong. The class file must be in the correct folder hierarchy for the package structure. If you do not understand Java packages yet, you need to stop and learn that before doing anything else.
 
GeeCON Prague 2014
 
subject: bean error