Wrox Home  
Search P2P Archive for: Go

  Return to Index  

apache_tomcat thread: JSP and JavaBeans


Message #1 by "Kunal Jaggi" <nareshjaggi@y...> on Mon, 3 Mar 2003 18:06:03
I am finding problems using a simple Bean in a JSP Page.
The bean code is given below:
public class HelloBean {
private String name = "World";
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
I have placed the source code and the .class file in 
install_dir/webapps/ROOT/WEB-INF/classes directory
The JSP code is as under:
<%-- hello3.jsp --%>
<%@ page import="HelloBean" %>
<jsp:useBean id="hello" class="HelloBean">
<jsp:setProperty name="hello" property="*" />
</jsp:useBean>
<HTML>
<HEAD><TITLE>Hello</TITLE></HEAD>
<BODY>
<H1>
Hello, <jsp:getProperty name="hello" property="name" />
</H1>
</BODY>
</HTML> 
I have placed the hello3.jsp file in install_dir/webapps/ROOT directory

Now when I try to run the JSP file using 
http://localhost:8080/hello3.jsp , there is a compiler error indicating 
that the import statement is wrong. Where the Bean class file should be 
placed?

I am Using Tomcat 4.1.12 

Regards,
Kunal Jaggi
SCJP2 

Message #2 by Archana Annamaneni <akpally@y...> on Mon, 3 Mar 2003 15:47:57 -0800 (PST)
Hi ,

I am really not sure about placing and accessing the
bean yet , I just satrted reading all this stuff.

A bean should implement Serializable interface and
have a no argumnet constructor.

So your code should look something like this.
 
public class HelloBean implements java.io.Serializable
 {
private String name = "World";

HelloBean(){}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

I hope that helps somewhat.

Bye
Archana
--- Kunal Jaggi <nareshjaggi@y...> wrote:
> I am finding problems using a simple Bean in a JSP
> Page.
> The bean code is given below:
> public class HelloBean {
> private String name = "World";
> public void setName(String name) {
> this.name = name;
> }
> public String getName() {
> return name;
> }
> }
> I have placed the source code and the .class file in
> 
> install_dir/webapps/ROOT/WEB-INF/classes directory
> The JSP code is as under:
> <%-- hello3.jsp --%>
> <%@ page import="HelloBean" %>
> <jsp:useBean id="hello" class="HelloBean">
> <jsp:setProperty name="hello" property="*" />
> </jsp:useBean>
> <HTML>
> <HEAD><TITLE>Hello</TITLE></HEAD>
> <BODY>
> <H1>
> Hello, <jsp:getProperty name="hello" property="name"
> />
> </H1>
> </BODY>
> </HTML> 
> I have placed the hello3.jsp file in
> install_dir/webapps/ROOT directory
> 
> Now when I try to run the JSP file using 
> http://localhost:8080/hello3.jsp , there is a
> compiler error indicating 
> that the import statement is wrong. Where the Bean
> class file should be 
> placed?
> 
> I am Using Tomcat 4.1.12 
> 
> Regards,
> Kunal Jaggi
> SCJP2 
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
Message #3 by "karthikeyan.balasubramanian" <karthikeyan.balasubramanian@a...> on Tue, 4 Mar 2003 12:39:11 +0530
I dont think so.  Its not mandatory.  Hey btw did you try putting your bean
inside a package.

I believe tomcat generally forces us to use package when calling bean.  So
yours should be

something like

<%@ page import="CompanyName.HelloBean" %>

package CompanyName;

 public class HelloBean {
......................

PS : Try creating a separate context and work on dont use ROOT..


Hope this helps.

Have a great  day.

Karthikeyan B

----- Original Message -----
From: "Archana Annamaneni" <akpally@y...>
To: "Tomcat" <apache_tomcat@p...>
Sent: Tuesday, March 04, 2003 5:17 AM
Subject: [apache_tomcat] Re: JSP and JavaBeans


>
> Hi ,
>
> I am really not sure about placing and accessing the
> bean yet , I just satrted reading all this stuff.
>
> A bean should implement Serializable interface and
> have a no argumnet constructor.
>
> So your code should look something like this.
>
> public class HelloBean implements java.io.Serializable
>  {
> private String name = "World";
>
> HelloBean(){}
> public void setName(String name) {
> this.name = name;
> }
> public String getName() {
> return name;
> }
> }
>
> I hope that helps somewhat.
>
> Bye
> Archana
> --- Kunal Jaggi <nareshjaggi@y...> wrote:
> > I am finding problems using a simple Bean in a JSP
> > Page.
> > The bean code is given below:
> > public class HelloBean {
> > private String name = "World";
> > public void setName(String name) {
> > this.name = name;
> > }
> > public String getName() {
> > return name;
> > }
> > }
> > I have placed the source code and the .class file in
> >
> > install_dir/webapps/ROOT/WEB-INF/classes directory
> > The JSP code is as under:
> > <%-- hello3.jsp --%>
> > <%@ page import="HelloBean" %>
> > <jsp:useBean id="hello" class="HelloBean">
> > <jsp:setProperty name="hello" property="*" />
> > </jsp:useBean>
> > <HTML>
> > <HEAD><TITLE>Hello</TITLE></HEAD>
> > <BODY>
> > <H1>
> > Hello, <jsp:getProperty name="hello" property="name"
> > />
> > </H1>
> > </BODY>
> > </HTML>
> > I have placed the hello3.jsp file in
> > install_dir/webapps/ROOT directory
> >
> > Now when I try to run the JSP file using
> > http://localhost:8080/hello3.jsp , there is a
> > compiler error indicating
> > that the import statement is wrong. Where the Bean
> > class file should be
> > placed?
> >
> > I am Using Tomcat 4.1.12
> >
> > Regards,
> > Kunal Jaggi
> > SCJP2
> >
>
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Tax Center - forms, calculators, tips, more
> http://taxes.yahoo.com/
>
>


Message #4 by "ashima gupta" <ashima.gupta@c...> on Tue, 11 Mar 2003 02:09:15
> I am finding problems using a simple Bean in a JSP Page.
T> he bean code is given below:
p> ublic class HelloBean {
p> rivate String name = "World";
p> ublic void setName(String name) {
t> his.name = name;
}> 
p> ublic String getName() {
r> eturn name;
}> 
}> 
I>  have placed the source code and the .class file in 
i> nstall_dir/webapps/ROOT/WEB-INF/classes directory
T> he JSP code is as under:
<> %-- hello3.jsp --%>
<> %@ page import="HelloBean" %>
<> jsp:useBean id="hello" class="HelloBean">
<> jsp:setProperty name="hello" property="*" />
<> /jsp:useBean>
<> HTML>
<> HEAD><TITLE>Hello</TITLE></HEAD>
<> BODY>
<> H1>
H> ello, <jsp:getProperty name="hello" property="name" />
<> /H1>
<> /BODY>
<> /HTML> 
I>  have placed the hello3.jsp file in install_dir/webapps/ROOT directory

> Now when I try to run the JSP file using 
h> ttp://localhost:8080/hello3.jsp , there is a compiler error indicating 
t> hat the import statement is wrong. Where the Bean class file should be 
p> laced?

> I am Using Tomcat 4.1.12 

> Regards,
K> unal Jaggi
S> CJP2 

Message #5 by "ashima gupta" <ashima.gupta@c...> on Tue, 11 Mar 2003 02:10:57
I don't think you need to have an import statement at all for the bean. 
Just the USEBEAN should be fine. 

Ashima



> I am finding problems using a simple Bean in a JSP Page.
T> he bean code is given below:
p> ublic class HelloBean {
p> rivate String name = "World";
p> ublic void setName(String name) {
t> his.name = name;
}> 
p> ublic String getName() {
r> eturn name;
}> 
}> 
I>  have placed the source code and the .class file in 
i> nstall_dir/webapps/ROOT/WEB-INF/classes directory
T> he JSP code is as under:
<> %-- hello3.jsp --%>
<> %@ page import="HelloBean" %>
<> jsp:useBean id="hello" class="HelloBean">
<> jsp:setProperty name="hello" property="*" />
<> /jsp:useBean>
<> HTML>
<> HEAD><TITLE>Hello</TITLE></HEAD>
<> BODY>
<> H1>
H> ello, <jsp:getProperty name="hello" property="name" />
<> /H1>
<> /BODY>
<> /HTML> 
I>  have placed the hello3.jsp file in install_dir/webapps/ROOT directory

> Now when I try to run the JSP file using 
h> ttp://localhost:8080/hello3.jsp , there is a compiler error indicating 
t> hat the import statement is wrong. Where the Bean class file should be 
p> laced?

> I am Using Tomcat 4.1.12 

> Regards,
K> unal Jaggi
S> CJP2 


  Return to Index