You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Robbert <ro...@gmail.com> on 2006/11/16 02:12:46 UTC

Re: CSS not being used when a Servlet is involved

Apologies for the late reply. I've had some more pressing to attend to.

Christopher Schultz-2 wrote:
> 
> Robbert,
> 
>> Christopher Schultz-2 wrote:
>>> You have your process turned upside down, here.
>> 
>> Why is the process turned upside down, exactly? Or rather, is there any
>> benefit in mapping /index to a Servlet and then forwarding to a JSP
>> instead
>> of going to JSP pages which invoke my Servlet?
>> This probably boils down to the following question: When do you use a JSP
>> and when do you use a Servlet?
> 
> Well, that's a somewhat philosophical and often religious argument. I
> think that one ought to use JSPs for quick-and-dirty hacked logic, /or/
> for display purposes only. Your "real work" ought to be done in
> servlets. I find the error handling more straightforward and less messy
> than in JSPs (although a JSP does get translated into a servlet before
> execution, so really they are exactly the same thing).

I have to agree totally with that. It's the more logical thing to do.


Christopher Schultz-2 wrote:
> At any rate, what you are trying to do is:
> 
> 1) Perform some logic in your servlet.
> 2) Emit some output to the client.
> 
> Since you want to do those 2 things, in that order, why invoke #2 first,
> which calls-back to #1, and then emits the output? It's far more natural
> to invoke the servlet and then have it forward to the JSP. Note that
> this is an internal forward, so the browser has no idea that control has
> been transferred from the servlet to the JSP. Of course, you could also
> use an HTTP FORWARD if that's what you really wanted to do.

True... I hadn't thought it about it like that. Still, no one knows that the
servlet is being executed because it happens while the page is being loaded.

If I do it that way (let my Servlet catch all the requests, do some logic
and forward to the JSP), then I won't have any problems with CSS or images,
right? Since the Servlet is no longer invoked via the JSP, it shouldn't be a
problem.
Because right now, I can get the CSS to work, but the images aren't being
shown for some reason or another (even though the links in the CSS file are
correct).


Christopher Schultz-2 wrote:
> > Struts sounds like a good framework. I'm not too experienced with those
> but
>> I take it that won't be hard to use. It's just how we were learned to
>> code.
>> So it never seemed to me as if the process was reversed.
> 
> Whether or not you use struts, I highly recommend that you avoid tricks
> like calling a servlet from a JSP in order to execute your business
> logic. If you have a waterfall-style logical flow (i.e. execute servlet
> first, then JSP), it's only natural to have the flow actually do that.
> It's okay if you application isn't 100% "pull-based" ;)
> 
> -chris
> 
> 

It seemed like a good way of doing things at the time, since the Servlet's
output is not needed for the page itself. :p But I am doing more things than
necessary, yeah.
-- 
View this message in context: http://www.nabble.com/CSS-not-being-used-when-a-Servlet-is-involved-tf2521410.html#a7369839
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: CSS not being used when a Servlet is involved

Posted by Robbert <ro...@gmail.com>.


Christopher Schultz-2 wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Robert,
> 
> Robbert wrote:
>> Christopher Schultz-2 wrote:
>>> Whether or not you use struts, I highly recommend that you avoid tricks
>>> like calling a servlet from a JSP in order to execute your business
>>> logic. If you have a waterfall-style logical flow (i.e. execute servlet
>>> first, then JSP), it's only natural to have the flow actually do that.
>>> It's okay if you application isn't 100% "pull-based" ;)
>>>
>>> -chris
>> 
>> It seemed like a good way of doing things at the time, since the
>> Servlet's
>> output is not needed for the page itself. :p But I am doing more things
>> than
>> necessary, yeah.
> 
> Aah, I see that you're saying. Often, servlets emit no output. I would
> say that /almost all/ servlets emit no output, but that they are
> generally used to set up the request so that control can be passed to an
> output-generating mechanism (JSP, Velocity, whatever). This is the
> natural way that pretty much everybody does servlet programming.
> 
> The best reason to switch is that you are having problems with your
> awkward setup, eh? ;)
> 
> Good luck,
> - -chris
> 
> 

Well, switching things around a bit worked. After reinstalling Tomcat Apache
and ant completely and starting from scratch, I managed to get it working.
Before a page is called, it invokes the StatistiekServlet and then does a
requestDispatcher to the page that the user wants to see (e.g.: The user
requests /Index, the StatistiekServlet registers the necessary hits and
forwards to /pages/Index.jsp).

At least I now get images and everything is being processed correctly.
There's another problem, but I'll get to that in another thread.

Thanks for your outstanding help! I owe you a beer. ;)

Regards,
Robbert

-- 
View this message in context: http://www.nabble.com/CSS-not-being-used-when-a-Servlet-is-involved-tf2521410.html#a7507314
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: CSS not being used when a Servlet is involved

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert,

Robbert wrote:
> Christopher Schultz-2 wrote:
>> Whether or not you use struts, I highly recommend that you avoid tricks
>> like calling a servlet from a JSP in order to execute your business
>> logic. If you have a waterfall-style logical flow (i.e. execute servlet
>> first, then JSP), it's only natural to have the flow actually do that.
>> It's okay if you application isn't 100% "pull-based" ;)
>>
>> -chris
> 
> It seemed like a good way of doing things at the time, since the Servlet's
> output is not needed for the page itself. :p But I am doing more things than
> necessary, yeah.

Aah, I see that you're saying. Often, servlets emit no output. I would
say that /almost all/ servlets emit no output, but that they are
generally used to set up the request so that control can be passed to an
output-generating mechanism (JSP, Velocity, whatever). This is the
natural way that pretty much everybody does servlet programming.

The best reason to switch is that you are having problems with your
awkward setup, eh? ;)

Good luck,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFXG/29CaO5/Lv0PARAshOAKCGunDTgL5egrEieSYKwS7Hi48F/ACcCsh4
TeB3BczhDR/32arMc1MjpwA=
=HsIr
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org