Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean error

 
Sanjay Izardar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sanjay Izardar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear,
I was not aware of that.
Why we actually want to make our JSPs hidden?
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic