Avatar billede jadirir Nybegynder
12. august 2003 - 20:42 Der er 15 kommentarer og
1 løsning

Beans and Tomcat 5.0.6

Hi all
Could any one help me how to use java beans with Tomcat 5.0.6?
My question is where to place java beans in Tomcat directory structure?.
Thanks
Avatar billede arne_v Ekspert
12. august 2003 - 20:46 #1
webapps/yourapp/WEB-INF/classes/yourpackage/YourClass.class
Avatar billede jadirir Nybegynder
12. august 2003 - 20:57 #2
Tomcat could not generate the class file i.e. could not compile the beans file.
Thanks
Avatar billede arne_v Ekspert
12. august 2003 - 21:00 #3
No - you need to compile the servlets and the beans yourself.

Tomcat will compile JSP pages.

[at least that is how Tomcat 4 and the 3-4 other servers I have tried are
doing it - I belive Tomcat 5 to be similar]
Avatar billede jadirir Nybegynder
12. august 2003 - 21:16 #4
Hi Arne_v
I compile it seperatly and make it jar file and place it webapps/yourapp/WEB-INF/classes/, but it does not help. The URL I wrote: http://localhost:8080/myappl/bean_user.jsp
Avatar billede arne_v Ekspert
12. august 2003 - 21:18 #5
Sorry.

jar-files is different - they should be in:

webapps/yourapp/WEB-INF/lib/mylibrary.jar
Avatar billede jadirir Nybegynder
12. august 2003 - 21:42 #6
Hi arne
I try it but it does not help. The big question is: How jsp file can find the class file? (Throught the classpath or .xml file)
Thanks your time
Avatar billede arne_v Ekspert
12. august 2003 - 21:54 #7
The server automatically set classpath to all jar files in the lib directory.
Avatar billede jadirir Nybegynder
12. august 2003 - 22:04 #8
The jsp file could not find the bean class. And it shows an exception (classnotfound), that could not find the bean.
Avatar billede arne_v Ekspert
12. august 2003 - 22:14 #9
Kan du vise mig det relevant JSP kode og en listning af hvordan beanen ligger
i jar filen ?
Avatar billede arne_v Ekspert
12. august 2003 - 22:14 #10
Sorry.

Could you show me the relevant JSP code and a listing of how the bean
are in the jar file ?
Avatar billede arne_v Ekspert
12. august 2003 - 23:15 #11
You are aware of that 5.0.6 is an alpha version ?
Avatar billede jadirir Nybegynder
14. august 2003 - 10:24 #12
Hi Arne
Sorry for the delay the following is the JSP code:
<jsp:useBean id="formbean" class="FormBean"/>
<jsp:setProperty name="formbean" property=
"*"/>
<HTML>
<HEAD>
<TITLE>Form Example</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffcc">
<% if (request.getParameter("name")==null
&& request.getParameter("email") == null) { %>
<CENTER>
<H2>User Info Request Form </H2>
<form method="GET" action="process2.jsp">
<P>
Your name: <input type="text" name=
"name" size=27>
<p>
Your email: <input type="text" name=
"email" size=27>
<P>
<input type="submit" value="Process">
</FORM>
</CENTER>
<% } else { %>
<P>
<B>You have provided the following info</B>:
<P>
<B>Name</B>: <jsp:getProperty name=
"formbean"
property="name"/>
<P>
<B>Email</B>: <jsp:getProperty
name="formbean" property="email"/>
<% } %>
</BODY>
</HTML>
Avatar billede arne_v Ekspert
14. august 2003 - 12:24 #13
Og hvordan ligger FormBean.class i jar-filen ?
Avatar billede jadirir Nybegynder
14. august 2003 - 12:58 #14
Following is the Bean code, which I make the jar file (jar cvf mybean.jar *.class).

//package beans;
import java.io.*;
public class FormBean implements Serializable {
    private String name;
    private String email;
    public FormBean() {
        name = null;
        email = null;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getEmail() {
        return email;
    }
}
Avatar billede arne_v Ekspert
14. august 2003 - 13:29 #15
Mit gæt er at det er et klassisk "no package" problem.

Så prøv og:

1)  indsæt

package myutils;

øvert i java filen.

2)  flyt FormBean.java ned i et nyt directory myutils
    (myutils\FormBean.java)

3)  compile igen

4)  lav jar-filen med:

jar cvf mybean.jar myutils\*.class

5)  kopier mybean.jar til webapps\myappl\WEB-INF\lib

6)  ret JSP til

<jsp:useBean id="formbean" class="myutils.FormBean"/>

7)  prøv igen
Avatar billede jadirir Nybegynder
14. august 2003 - 19:23 #16
Thank you very much Arne. I succed got it.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester