• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

bean error

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)

 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 >
 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 54
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic