Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #21207 > unrolled thread
| Started by | Roma Asnani <romaasnani@gmail.com> |
|---|---|
| First post | 2013-01-08 04:19 -0800 |
| Last post | 2013-01-09 11:20 -0800 |
| Articles | 9 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
Web browser in java Roma Asnani <romaasnani@gmail.com> - 2013-01-08 04:19 -0800
Re: Web browser in java lipska the kat <lipskathekat@yahoo.co.uk> - 2013-01-08 13:10 +0000
Re: Web browser in java Arne Vajhøj <arne@vajhoej.dk> - 2013-01-09 21:31 -0500
Re: Web browser in java lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-01-10 09:57 +0000
Re: Web browser in java Arne Vajhøj <arne@vajhoej.dk> - 2013-01-08 20:10 -0500
Re: Web browser in java lipska the kat <lipskathekat@yahoo.co.uk> - 2013-01-09 09:12 +0000
Re: Web browser in java Arne Vajhøj <arne@vajhoej.dk> - 2013-01-09 21:21 -0500
Re: Web browser in java lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-01-10 08:46 +0000
Re: Web browser in java Roedy Green <see_website@mindprod.com.invalid> - 2013-01-09 11:20 -0800
| From | Roma Asnani <romaasnani@gmail.com> |
|---|---|
| Date | 2013-01-08 04:19 -0800 |
| Subject | Web browser in java |
| Message-ID | <79904e78-2885-4a7f-a3e2-f260ffb6063a@googlegroups.com> |
Want to create a web browser but unable to handle cookies can any one help? I get some source from this link http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html but it display a simple browser but has no cookies or session handling.
[toc] | [next] | [standalone]
| From | lipska the kat <lipskathekat@yahoo.co.uk> |
|---|---|
| Date | 2013-01-08 13:10 +0000 |
| Message-ID | <X_idnUUL5Mh5h3HNnZ2dnUVZ8jOdnZ2d@bt.com> |
| In reply to | #21207 |
On 08/01/13 12:19, Roma Asnani wrote: > Want to create a web browser but unable to handle cookies can any one help? > I get some source from this link > http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html > but it display a simple browser but has no cookies or session handling. Hi Firstly it is not the browser that maintains a session it is the server. When you make a request for a web page your browser looks in the place where it stores cookies (if you are writing a web browser this can be anywhere you like, a browser usually writes cookies to disk) and adds any cookies it finds that match the URL you are requesting to the request. Only then will it send the request So, you need a way of searching your cookie store, finding any cookies that 'belong' to the URL you are requesting and adding the resulting cookies to the request before you send it. When your request hits the server, you access the cookies by extracting them from the request, actually if you are using a Java servlet container like Tomcat you don't need to bother with explicitly managing session cookies, If a session exists (in other words if a valid session cookie was sent by the browser) Tomcat will retrieve the session using the contents of the cookie to 'lookup' the session in it's session store. If a session doesn't exist or if it has timed out, Tomcat will make a new one, create a cookie with a lookup key in it (amongst other things) and add the cookie to the response. If you are making a request to a server that understands how to use cookies to maintain state then all you have to do is extract cookies from a response to your original request, store them somewhere safe, and add them to your next request, the server will take care of the rest. The simplified sequence of events goes something like this 1. Make a request to foo.bar.com Before you actually send the request but after you know the target 2. Search your browser cookie store for any cookies that belong to foo.bar.com, if you find them, add them to the request. 3. send the request 4. When the server replies, parse the response and extract any cookies written by the server, one of these is probably your session key. Save them to your cookie store. 5. make a new request to foo.bar.com adding the session cookie to the request. bingo! you have a session Internet rfc2616 might be of interest but it's a bit of a head banger lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-01-09 21:31 -0500 |
| Message-ID | <50ee2819$0$294$14726298@news.sunsite.dk> |
| In reply to | #21208 |
On 1/8/2013 8:10 AM, lipska the kat wrote: > On 08/01/13 12:19, Roma Asnani wrote: >> Want to create a web browser but unable to handle cookies can any one >> help? >> I get some source from this link >> http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html >> >> but it display a simple browser but has no cookies or session handling. > > Firstly it is not the browser that maintains a session it is the server. It needs info from the client to do so. > When you make a request for a web page your browser looks in the place > where it stores cookies (if you are writing a web browser this can be > anywhere you like, a browser usually writes cookies to disk) and adds > any cookies it finds that match the URL you are requesting to the > request. Only then will it send the request > > So, you need a way of searching your cookie store, finding any cookies > that 'belong' to the URL you are requesting and adding the resulting > cookies to the request before you send it. Cookies with session id should never be stored on disk. > When your request hits the server, you access the cookies by extracting > them from the request, actually if you are using a Java servlet > container like Tomcat you don't need to bother with explicitly managing > session cookies, If a session exists (in other words if a valid session > cookie was sent by the browser) Tomcat will retrieve the session using > the contents of the cookie to 'lookup' the session in it's session > store. If a session doesn't exist or if it has timed out, Tomcat will > make a new one, create a cookie with a lookup key in it (amongst other > things) and add the cookie to the response. Depends. JSP pages do so. Servlets do not. > If you are making a request to a server that understands how to use > cookies to maintain state then all you have to do is extract cookies > from a response to your original request, store them somewhere safe, and > add them to your next request, the server will take care of the rest. > > The simplified sequence of events goes something like this > > 1. Make a request to foo.bar.com > > Before you actually send the request but after you know the target > > 2. Search your browser cookie store for any cookies that belong to > foo.bar.com, if you find them, add them to the request. > > 3. send the request > > 4. When the server replies, parse the response and extract any cookies > written by the server, one of these is probably your session key. Save > them to your cookie store. > > 5. make a new request to foo.bar.com adding the session cookie to the > request. > > bingo! you have a session You can skip #2 (unless you need other info than session that are stored in cookies). But I would let #5 add all cookies retrieved in #4, because they are most likely all needed (if not then there were no reason to set them). Arne
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
|---|---|
| Date | 2013-01-10 09:57 +0000 |
| Message-ID | <ULednZIRupABDXPNnZ2dnUVZ8n6dnZ2d@bt.com> |
| In reply to | #21278 |
On 10/01/13 02:31, Arne Vajhøj wrote: > On 1/8/2013 8:10 AM, lipska the kat wrote: >> On 08/01/13 12:19, Roma Asnani wrote: >>> Want to create a web browser but unable to handle cookies can any one >>> help? >>> I get some source from this link >>> http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html >>> >>> >>> but it display a simple browser but has no cookies or session handling. >> >> Firstly it is not the browser that maintains a session it is the server. > > It needs info from the client to do so. <patience mode> Yes, well we cover this don't we. </patience mode> [snip] > Depends. JSP pages do so. Servlets do not. JSP 'pages' compile to servlets before first execution. The default value of the needsSession parameter passed to JspFactory.getPageContext(...) is true, this can be changed in the page directive. But I'll conceed the point that the default behaviour of a servlet compiled from a jsp is to create a new session if one does not already exist. I would not rely on this however if I was developing an application that depended on serverside session management.. >> If you are making a request to a server that understands how to use >> cookies to maintain state then all you have to do is extract cookies >> from a response to your original request, store them somewhere safe, and >> add them to your next request, the server will take care of the rest. >> >> The simplified sequence of events goes something like this >> >> 1. Make a request to foo.bar.com >> >> Before you actually send the request but after you know the target >> >> 2. Search your browser cookie store for any cookies that belong to >> foo.bar.com, if you find them, add them to the request. >> >> 3. send the request >> >> 4. When the server replies, parse the response and extract any cookies >> written by the server, one of these is probably your session key. Save >> them to your cookie store. >> >> 5. make a new request to foo.bar.com adding the session cookie to the >> request. >> >> bingo! you have a session > > You can skip #2 (unless you need other info than > session that are stored in cookies > > But I would let #5 add all cookies retrieved in #4, > because they are most likely all needed (if not then > there were no reason to set them). The browser doesn't know if it's taking part in a session or not does it It doesn't need to know, all it needs to do is add the cookies to the request, how can it know if it needs to add cookies or not, it just does, any and every time. If there is a cookie for foo.bar.com at #2 it adds it, session cookie or not session cookie. Skipping the addition of a time valid cookie is not an option really is it. lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-01-08 20:10 -0500 |
| Message-ID | <50ecc3a6$0$293$14726298@news.sunsite.dk> |
| In reply to | #21207 |
On 1/8/2013 7:19 AM, Roma Asnani wrote: > Want to create a web browser but unable to handle cookies can any one help? > I get some source from this link > http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html > but it display a simple browser but has no cookies or session handling. I think the right way is to subclass JEditorPane and override getStream(URL) with a method that uses Apache HttpClient instead of HttpURLConnection. Arne
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <lipskathekat@yahoo.co.uk> |
|---|---|
| Date | 2013-01-09 09:12 +0000 |
| Message-ID | <dq-dnQyWMeIBqXDNnZ2dnUVZ7qGdnZ2d@bt.com> |
| In reply to | #21233 |
On 09/01/13 01:10, Arne Vajhøj wrote: > On 1/8/2013 7:19 AM, Roma Asnani wrote: >> Want to create a web browser but unable to handle cookies can any one >> help? >> I get some source from this link >> http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html >> >> but it display a simple browser but has no cookies or session handling. > > I think the right way is to subclass JEditorPane and > override getStream(URL) with a method that uses > Apache HttpClient instead of HttpURLConnection. It depends. If the object of the exercise is to understand the mechanics of cookie handing then 'doing it yourself' is a great learning exercise. If however the object of the exercise is to demonstrate your ability to delegate responsibility then using HttpClient and a rendering engine and some other bits and pieces would probably earn you a good grade. Horses for courses I guess. lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-01-09 21:21 -0500 |
| Message-ID | <50ee2597$0$287$14726298@news.sunsite.dk> |
| In reply to | #21244 |
On 1/9/2013 4:12 AM, lipska the kat wrote: > On 09/01/13 01:10, Arne Vajhøj wrote: >> On 1/8/2013 7:19 AM, Roma Asnani wrote: >>> Want to create a web browser but unable to handle cookies can any one >>> help? >>> I get some source from this link >>> http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html >>> >>> >>> but it display a simple browser but has no cookies or session handling. >> >> I think the right way is to subclass JEditorPane and >> override getStream(URL) with a method that uses >> Apache HttpClient instead of HttpURLConnection. > > It depends. > > If the object of the exercise is to understand the mechanics of cookie > handing then 'doing it yourself' is a great learning exercise. Given that the page used as starting point does not mention the word cookies and the code does not use any network code it all (it just use the setPage method with an URL), then that is not very likely. Arne
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
|---|---|
| Date | 2013-01-10 08:46 +0000 |
| Message-ID | <J8mdnU6dDtd94nPNnZ2dnUVZ8l-dnZ2d@bt.com> |
| In reply to | #21277 |
On 10/01/13 02:21, Arne Vajhøj wrote: > On 1/9/2013 4:12 AM, lipska the kat wrote: >> On 09/01/13 01:10, Arne Vajhøj wrote: >>> On 1/8/2013 7:19 AM, Roma Asnani wrote: >>>> Want to create a web browser but unable to handle cookies can any one >>>> help? >>>> I get some source from this link >>>> http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html [snip] > Given that the page used as starting point does > not mention the word cookies and the code does > not use any network code it all (it just use > the setPage method with an URL), then that is not > very likely. Really, hmm... the clue is in the question isn't it "but it display a simple browser but has no cookies or session handling" This implies to me that the OP was confused as to the allocation of responsibility between the browser/client and the server when it comes to the implementation of a stateful interaction over a stateless protocol. Understanding the session cookie handling mechanism would inform the user of his misapprehension rather better than employing HttpClient which ... and I quote the documentation here [features] Automatic Cookie handling for reading Set-Cookie: headers from the server and sending them back out in a Cookie: header when appropriate. Or maybe you disagree. lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2013-01-09 11:20 -0800 |
| Message-ID | <mlgre8ht4oa5tko0ri5ph36hl2ai6gi58g@4ax.com> |
| In reply to | #21207 |
On Tue, 8 Jan 2013 04:19:18 -0800 (PST), Roma Asnani <romaasnani@gmail.com> wrote, quoted or indirectly quoted someone who said : >Want to create a web browser but unable to handle cookies can any one help? >I get some source from this link >http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html >but it display a simple browser but has no cookies or session handling. See http://mindprod.com/jgloss/cookie.html -- Roedy Green Canadian Mind Products http://mindprod.com Students who hire or con others to do their homework are as foolish as couch potatoes who hire others to go to the gym for them.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web