JSP newbie - can I use JSP to access exiting java classes withoutre-write to javabeans

Discussion in 'Java' started by terry433iid@yahoo.com, Mar 16, 2008.

  1. Guest

    Hi,
    I have access to existing Java classes for users/hardware written
    by members of my team, and want to write some web-pages to query and
    display this data using JSP . Do I need to re-write the Java classes
    as java beans and utilise the "usebean" call to import this into my
    JSP (not a solution I'd like) or is there another way I can get access
    to current Java classes that are not Javabeans...????
    thanks
    terry
    , Mar 16, 2008
    #1
    1. Advertising

  2. Guest

    On Mar 16, 5:45 pm, "" <>
    wrote:
    > Hi,
    > I have access to existing Java classes for users/hardware written
    > by members of my team, and want to write some web-pages to query and
    > display this data using JSP . Do I need to re-write the Java classes
    > as java beans and utilise the "usebean" call to import this into my
    > JSP (not a solution I'd like) or is there another way I can get access
    > to current Java classes that are not Javabeans...????
    > thanks
    > terry


    Absolutely. Instead
    <jsp:useBean id="commander" class="abc.xyz.Commander"
    scope="session"></jsp:useBean>
    <%= commander%>

    you always can use

    <%
    abc.xyz.Commander commander= new abc.xyz.Commander();
    out.print(commander);
    %>

    If you like, of course ;)

    Alex.
    http://www.myjavaserver.com/~alexfromohio/
    , Mar 16, 2008
    #2
    1. Advertising

  3. Lew Guest

    "" wrote:
    >> I have access to existing Java classes for users/hardware written
    >> by members of my team, and want to write some web-pages to query and
    >> display this data using JSP . Do I need to re-write the Java classes
    >> as java beans and utilise the "usebean"


    Please be careful with your spelling on tag names and such.

    >> call to import this into my JSP (not a solution I'd like) or is there another way I can get access
    >> to current Java classes that are not Javabeans...????


    wrote:
    > Absolutely. Instead
    > <jsp:useBean id="commander" class="abc.xyz.Commander"
    > scope="session"></jsp:useBean>
    > <%= commander%>
    >
    > you always can use
    >
    > <%
    > abc.xyz.Commander commander= new abc.xyz.Commander();
    > out.print(commander);
    > %>
    >
    > If you like, of course ;)


    Which, hopefully, you won't, as it's terrible style. Ideally there won't be
    any scriptlet at all in your JSP.

    The good news is that there are at least two ways to tie in to your existing
    code. Bear in mind that tying in to existing code is one of the main things
    we do in Java.

    One way is to follow the "Model 2" version of the Model-View-Controller
    pattern for your Web app. The JSP will use JSTL and Expression Language (EL);
    not a <jsp:useBean> tag in sight. That will be the View. The Model will be a
    thin wrapper of (bean) classes that manage the interaction with the existing
    library of interest. The wrapper will assemble an object that contains
    various information that you are going to display, absent any display or
    formatting meta-information. The Controller is a servlet that is the target
    of the form submission from a JSP. This servlet will unpack the request and
    pass relevant data to the wrapper. It will insert the result object into the
    request attributes, then forward() through a RequestDispatcher to an
    appropriate "next" JSP - the next View screen.

    Another way is to create custom tags that directly invoke the wrapper classes
    and present result data in the rendering of the tag.

    --
    Lew
    Lew, Mar 17, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Beach
    Replies:
    0
    Views:
    576
    Chris Beach
    Sep 8, 2003
  2. matt

    Javabeans and JSP's

    matt, Jan 24, 2004, in forum: Java
    Replies:
    2
    Views:
    342
  3. Philip McKee
    Replies:
    2
    Views:
    1,340
    Philip McKee
    Apr 20, 2004
  4. Vardan
    Replies:
    1
    Views:
    320
    Andrew Thompson
    Aug 8, 2004
  5. thecrow
    Replies:
    24
    Views:
    1,188
    John McGrath
    May 28, 2005
Loading...

Share This Page