Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   JSP and Vector (http://www.velocityreviews.com/forums/t390924-jsp-and-vector.html)

KevinRobinson 02-17-2007 08:25 AM

JSP and Vector
 
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



Boaz.Jan@gmail.com 02-17-2007 02:07 PM

Re: JSP and Vector
 
On Feb 17, 10:25 am, "KevinRobinson" <k.s.robin...@btinternet.com>
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?


Boaz.Jan@gmail.com 02-17-2007 04:24 PM

Re: JSP and Vector
 
On Feb 17, 4:07 pm, "Boaz....@gmail.com" <Boaz....@gmail.com> wrote:
> On Feb 17, 10:25 am, "KevinRobinson" <k.s.robin...@btinternet.com>
> 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/ap...r.html#include
and
http://java.sun.com/javaee/5/docs/tu...9.html#wp64684

hope i helped :)


Lew 02-17-2007 04:27 PM

Re: JSP and Vector
 
"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.


Boaz.Jan@gmail.com 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 02-17-2007 05:08 PM

Re: JSP and Vector
 
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


All times are GMT. The time now is 09:24 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.