Re: How could this possibly happen (HttpURLConnection + simple JSP page)



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
.



Relevant Pages

  • Re: Whats the real content type of XHTML?
    ... Is that something in the HTML file itself, ... This response consists of a number of headers followed by the ...
    (alt.html)
  • Re: Igor, pAPP toolkit questions
    ... Thanks for your response. ... Your toolkit has just been invaluable and I ... > headers have been fully prepared. ... you suggesting I add a datastructure there to maintain the HTML info ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: Need help to figure out urllib2.Request()
    ... I tried to open some web pages with urllib2.Request(url, data, headers), but ... data= account ... response = urllib2.urlopen ... html = response.read ...
    (comp.lang.python)
  • Re: Recursively scraping web pages for embedded links and files
    ... Tim- thank you again for your response. ... I've managed to get the HTML of a target page ... If you're new to working with HTML docs from Excel then it may be a long ... scrape multiple levels within the directory tree of a website. ...
    (microsoft.public.excel.programming)
  • Re: Dumb Question -- How do you get rid of Spaces in JSP Expression Form Data?
    ... LB Response: Obviously you are correct. ... And yes everybody is correct about HTML validation. ... realPath into the JavaBean class from the calling xxx.jsp file using ... And remember to always escape your output appropriately. ...
    (comp.lang.java.programmer)