JSP and Vector

Discussion in 'Java' started by KevinRobinson, Feb 17, 2007.

  1. Hi,

    Hope someone can help.

    I am using a Vector in a Servlet to return HTML to a JSP.
    The problem is that the HTML rows returned to the JSP include comma
    delimiters and the whole of the HTML code
    is contained in square brackets.

    The delimiters and brackets are visible in the JSP.

    How can I get rid of the delimiters and brackets or render them not visible?

    I have tried including <!-- --> but this doesn't work.

    Any ideas.

    Thanks in anticipation.

    Kevin
     
    KevinRobinson, Feb 17, 2007
    #1
    1. Advertising

  2. KevinRobinson

    Guest

    On Feb 17, 10:25 am, "KevinRobinson" <>
    wrote:
    > Hi,
    >
    > Hope someone can help.
    >
    > I am using a Vector in a Servlet to return HTML to a JSP.
    > The problem is that the HTML rows returned to the JSP include comma
    > delimiters and the whole of the HTML code
    > is contained in square brackets.
    >
    > The delimiters and brackets are visible in the JSP.
    >
    > How can I get rid of the delimiters and brackets or render them not visible?
    >
    > I have tried including <!-- --> but this doesn't work.
    >
    > Any ideas.
    >
    > Thanks in anticipation.
    >
    > Kevin


    can you show us your code or be more specific? how execly do you use a
    vector for this perphes?
     
    , Feb 17, 2007
    #2
    1. Advertising

  3. KevinRobinson

    Guest

    On Feb 17, 4:07 pm, "" <> wrote:
    > On Feb 17, 10:25 am, "KevinRobinson" <>
    > wrote:
    >
    >
    >
    >
    >
    > > Hi,

    >
    > > Hope someone can help.

    >
    > > I am using a Vector in a Servlet to return HTML to a JSP.
    > > The problem is that the HTML rows returned to the JSP include comma
    > > delimiters and the whole of the HTML code
    > > is contained in square brackets.

    >
    > > The delimiters and brackets are visible in the JSP.

    >
    > > How can I get rid of the delimiters and brackets or render them not visible?

    >
    > > I have tried including <!-- --> but this doesn't work.

    >
    > > Any ideas.

    >
    > > Thanks in anticipation.

    >
    > > Kevin

    >
    > can you show us your code or be more specific? how execly do you use a
    > vector for this perphes?- Hide quoted text -
    >
    > - Show quoted text -


    thats because the <%=pap%> automaticlly calls the Vector.tostring()
    method so it can be placed on the jsp
    and the Vector.tostring() method flushes the text with those
    delimters...
    so you have 2 options
    1) extend Vector and overide his tostring() method
    2) dont use a vector. you dont need it to add dynamic content to your
    JSP... if you insist on doing it this way (and i cant see any reason
    why to...) user StringBuffer to create the string HTML code and the do
    the <%=pap%> while "pap" is of type stringbuffer - the
    stringbuffer.tostring() returns a clean string and dont have the
    overhead of using a collection
    secondly, why cant you do the test if to show these HTML lines at the
    jsp as so:


    <% if (||your condition here||) { %>
    <form action=\"https://www.paypal.com/uk/cgi-bin/webscr\" method=
    \"post\">
    <input type=\"hidden\" name=\"cmd\" value=\"_cart\">
    <input type=\"hidden\" name=\"upload\"value=\"1\">
    <% } else { %>
    some other html code
    <% } %>

    the simplest way to do it...

    and if i missunderstood you and you only wanted to make a common
    object to generate this line... you can use the
    RequestDispatcher.include() method

    for more explantions about it goto
    http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/RequestDispatcher.html#include
    and
    http://java.sun.com/javaee/5/docs/tutorial/doc/Servlets9.html#wp64684

    hope i helped :)
     
    , Feb 17, 2007
    #3
  4. KevinRobinson

    Lew Guest

    "KevinRobinson" wrote:
    >> I am using a Vector in a Servlet to return HTML to a JSP.
    >> The problem is that the HTML rows returned to the JSP include comma
    >> delimiters and the whole of the HTML code
    >> is contained in square brackets.
    >>
    >> The delimiters and brackets are visible in the JSP.
    >>
    >> How can I get rid of the delimiters and brackets or render them not visible?
    >>
    >> I have tried including <!-- --> but this doesn't work.


    wrote:
    > can you show us your code or be more specific? how execly do you use a
    > vector for this perphes?


    And why?

    It is pretty pathological to pass HTML around as objects between servlets and
    JSPs. JSPs in the first place are designed for dynamic HTML generation.

    One of the most reliable design patterns for Web apps is the
    model-view-controller (MVC) architecture. There is a servlet that provides
    initial request parsing and dispatch to the model, or business logic, layer,
    then forwards the request to a JSP for display of the results. The JSP handles
    all aspects of HTML generation, but relies on the model layer to provide the
    data backing the view.

    I would suggest using ArrayList in lieu of Vector, but for that you should use
    neither for this purpose.

    -Lew
     
    Lew, Feb 17, 2007
    #4
  5. KevinRobinson

    Lew Guest

    KevinRobinson wrote:
    > Hi,
    >
    > Hope someone can help.
    >
    > I am using a Vector in a Servlet to return HTML to a JSP.
    > The problem is that the HTML rows returned to the JSP include comma
    > delimiters and the whole of the HTML code
    > is contained in square brackets.
    >
    > The delimiters and brackets are visible in the JSP.
    >
    > How can I get rid of the delimiters and brackets or render them not visible?
    >
    > I have tried including <!-- --> but this doesn't work.
    >
    > Any ideas.
    >
    > Thanks in anticipation.
    >
    > Kevin


    Your question got answers on the clj.programmer multipost.

    (Cross-posted to clj.misc and clj.programmer, followup to clj.programmer.)

    - Lew
     
    Lew, Feb 17, 2007
    #5
    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. pmatos
    Replies:
    6
    Views:
    23,821
  2. Replies:
    0
    Views:
    4,401
  3. Replies:
    8
    Views:
    1,930
    Csaba
    Feb 18, 2006
  4. Javier
    Replies:
    2
    Views:
    567
    James Kanze
    Sep 4, 2007
  5. Rushikesh Joshi
    Replies:
    0
    Views:
    366
    Rushikesh Joshi
    Jul 10, 2004
Loading...

Share This Page