Re: How could this possibly happen (HttpURLConnection + simple JSP page)
- From: James Westby <jw2328@xxxxxxxxxx>
- Date: Tue, 24 Jan 2006 17:02:14 GMT
phillip.s.powell@xxxxxxxxx wrote:
Looks a lot simpler than what I came up with, but I'm notorious for coming up with the most complex solution to things and having to have others make it simpler for me as I never think of it myself *sigh*
Not particularly difficult to come up with if you understand what a cookie is. It was suggested as teh first response to your post.
However, I do have one question: Why do you have response.setHeader() embedded within the HTML code? In PHP that would throw some nasty HTTP-related warnings and potentially break the page as you are changing the headers after HTML display?
I think you need to look again at the architecture of JSP pages.
You are not really writing HTML pages. You are writing code in a special format that is compiled in to a servlet, which is then executed by the server when the page is requested.
The other thing is that writing things "after HTML display" is probably very difficult as the display is done on the users computer when they have recieved the response.
You know you have some predefined variables in JSP pages, request, response, out. You get the request so that you know what the user wants. You get the response so that you can return this to them. out is merely the object returned by response.getOutputStream(). You know that the response has two sections, a header and body, and when you call out.println() you put stuff in the body. When you call setHeader() you put stuff in the header. Think of all the HTML you write in a page as being wrapped up in out.println(). I guess you understand all this, but worth clarifying for the next bit.
When you create a response for the user it does not necessarily get sent back as soon as you start, and more importantly the headers do not necessarily finish as soon as you start writing to the body. This allows you to manipulate the headers whenever you want, which can be convinient.
My guess is that this is different in PHP then, do you have to do all header stuff at the top of a page or something? If so then it will finish the headers in the reponse the moment you manipulate the body. Obviously this works fine in some cases, but could make some things difficult. I have seen PHP pages where one page is chopped up in to multiple fragments, how would you maipulate the headers in a fragment further down? I don't like this pattern at all, for one it makes the code almost impossible to read. I've seen mention of a Java thing called sitemesh somewhere that allows you to do something similar, but all the chunks are valid bits of HTML, and so it is much less confusing, but it may still have problems, I haven't used it so I don't know.
Hope you get all your problems sorted.
James .
- Follow-Ups:
- Re: How could this possibly happen (HttpURLConnection + simple JSP page)
- From: Oliver Wong
- Re: How could this possibly happen (HttpURLConnection + simple JSP page)
- References:
- How could this possibly happen (HttpURLConnection + simple JSP page)
- From: phillip.s.powell@xxxxxxxxx
- Re: How could this possibly happen (HttpURLConnection + simple JSP page)
- From: James Westby
- Re: How could this possibly happen (HttpURLConnection + simple JSP page)
- From: phillip.s.powell@xxxxxxxxx
- How could this possibly happen (HttpURLConnection + simple JSP page)
- Prev by Date: Re: How could this possibly happen (HttpURLConnection + simple JSP page)
- Next by Date: store object in database
- Previous by thread: Re: How could this possibly happen (HttpURLConnection + simple JSP page)
- Next by thread: Re: How could this possibly happen (HttpURLConnection + simple JSP page)
- Index(es):
Relevant Pages
|
|