How to use a class/bean from a servlet?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: How to use a class/bean from a servlet?

Hybrid View

  1. #1
    D.Yutzy Guest

    How to use a class/bean from a servlet?

    Hello,

    I'm fairly new to Java, but not programming, and simply cannot find an=20=

    example of using a server side bean or classe from inside a servlet...

    Any examples or help is appreciated.

  2. #2
    edavison Guest

    Re: How to use a class/bean from a servlet?


    Hi.

    I'm also fairly new to Java, but I think I may be able to help. I have used
    server side beans in servlets before by importing them into my class and
    instantiating them, then using their methods. Just like you would use java.util.*
    in your code include for example com.serverbean.bean.* and use it's methods,
    properties and events. The bean needs to be installed in a directory that
    is in you CLASSPATH too. That is what I have done and it seems to work ok
    for me. I hope this is what you were wanting out of a response.

    Eric

    D.Yutzy <dyutzy@copper.net> wrote:
    >Hello,
    >
    >I'm fairly new to Java, but not programming, and simply cannot find an=20=
    >
    >example of using a server side bean or classe from inside a servlet...
    >
    >Any examples or help is appreciated.



  3. #3
    D.Yutzy Guest

    Re: How to use a class/bean from a servlet?

    Just to be sure I understand this, in your example, I would have a folde=
    r=20
    structure of:

    <classpath>\com\serverbean\bean

    and under this would be .class files (beans)

    Or would it be:

    <classpath>\com\serverbean

    and bean.class is in the folder named above?


    > I'm also fairly new to Java, but I think I may be able to help. I hav=

    e=20
    used
    > server side beans in servlets before by importing them into my class a=

    nd
    > instantiating them, then using their methods. Just like you would use=

    =20
    java.util.*
    > in your code include for example com.serverbean.bean.* and use it's=20=


    methods,
    > properties and events. The bean needs to be installed in a directory =


    that
    > is in you CLASSPATH too. That is what I have done and it seems to wor=

    k=20
    ok
    > for me. I hope this is what you were wanting out of a response.




  4. #4
    edavison Guest

    Re: How to use a class/bean from a servlet?


    Yeah, in my example your bean would exist under the directory structure <classpath>\com\serverbean\bean\.
    For example <classpath>\com\serverbean\bean\yourbean.class. The * just means
    import everything in that package directory. If you write your own bean
    then you can use whatever directory structure that you want for the file.
    Otherwise you would use the bean developer's package information.

    You can also check out this link: http://java.sun.com/products/jdk/1.2...ngclasses.html
    and it will tell you more than you could possibly want to know about classes.



    Eric

    D.Yutzy <dyutzy@copper.net> wrote:
    >Just to be sure I understand this, in your example, I would have a folde=
    >r=20
    >structure of:
    >
    ><classpath>\com\serverbean\bean
    >
    >and under this would be .class files (beans)
    >
    >Or would it be:
    >
    ><classpath>\com\serverbean
    >
    >and bean.class is in the folder named above?
    >
    >
    >> I'm also fairly new to Java, but I think I may be able to help. I hav=

    >e=20
    >used
    >> server side beans in servlets before by importing them into my class a=

    >nd
    >> instantiating them, then using their methods. Just like you would use=

    >=20
    >java.util.*
    >> in your code include for example com.serverbean.bean.* and use it's=20=

    >
    >methods,
    >> properties and events. The bean needs to be installed in a directory

    =
    >
    >that
    >> is in you CLASSPATH too. That is what I have done and it seems to wor=

    >k=20
    >ok
    >> for me. I hope this is what you were wanting out of a response.

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center