You are not logged in.

#1 2013-01-23 14:05:46

From: Rennes - France
Registered: 2012-11-18
Posts: 6

[SOLVED] JAVA, servlet and Cookies

Hi everyone! I've a little issue with Cookies... I'm not sur how to use it with JAVA.

I explain :

I've to read an math equation on a website (for a challenge), and use it to return the solution on an other page.
But the website is requesting athentication, with a cookie (i know witch one, and where it is.)

I've already done a part of the code, just to read a web page :

import javax.servlet.*;

public class Main {
    public static String getHTML() {
        URL url;
        HttpURLConnection conn;
        BufferedReader rd;
        String line;
        String result = "";
        try {
            url = new URL("http://.......................YourURLHere......................");
            conn = (HttpURLConnection) url.openConnection();
            rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            while ((line = rd.readLine()) != null) {
                result += line;
        } catch (Exception e) {
        return result;
    public static void main(String[] args) {

I know there's method like

void AddCookie(Cookie myCookie)

But i'm not sure that's the one i should use, because apparently it must be use with the object HttpServletResponse.

So if anyone could help me, i keep searching on the web, thanks!

PS : sorry if my english isn't so good! >.<

EDIT : Okay so that was the setRequestProperty(String name, String key) method. I let it there, could be usefull!

Last edited by iduine (2013-01-23 14:24:25)


Board footer

Powered by FluxBB