I need help baking cookies

The geek forum. PHP, Perl, HTML, hardware questions etc.. it's all in here. Got a techie question? We'll sort you out. Ask your questions or post a link to your own site here!

I need help baking cookies

Postby glitch1501 » Tue Dec 20, 2005 9:07 am

ok, i have pretty much no knowledge of cookies other than what ive read off of cookiecentral.com

on this site i am working on, the first page you get to is a map with regions for this company, i want to make a cookie that will remember which region you click on so that it automatically goes to that region when you go back to the site...i hope its possible

any help would be greatly appreciated

glitch

Glitch's Photostream


He wants them to learn to walk and must therefore take away His hand; and if only the will to walk is really there, He is pleased even with their stumbles.

Image

Healing hands of God have mercy on our unclean souls
once again. Jesus Christ, Light of the World, burning
bright within our hearts forever. Freedom means love
without condition, without beginning or an end. Here's
my heart, let it be forever Yours, only You can make
every new day seem so new.
Every New Day - On Distant Shores - Five Iron Frenzy

Nail pierced hands they run with blood
A splitting brow forced by the thorns
His face is writhing with the pain yet it's comforting to me
Passion - Kutless
:thumb:
Image
User avatar
glitch1501
 
Posts: 2177
Joined: Mon Oct 20, 2003 6:50 pm
Location: the debris section

Postby Itachi » Tue Dec 20, 2005 10:34 am

Why
BEWARE of Itachi
Pink Dancer!!!- sister(consiter our selves sisters) :hug:
favorite parings
Naruto.........
1)SakuraxSasuke :sweat:
2)HinataxNaruto :jump:
3)TenTenxNeji :rock:
4)InoxShikamaru :cool:
5)HinataxKiba (don't ask) :sweat:
"I must of got'en lost on the path of life"-Kakashi
"How troublesome"-Shikamaru
"I'm going to be the future Hokage"-Naruto
In every quizilla quiz on Naruto i'm........
hinata :angel:
itachi !!
gaara ????
" There is nothig you can say that will take me away from this life. There is nothig you can do to Shut me Up when I'm speeking the Truth."- Kutless
Thousand Foot Krutch favorite songs
1)move :rock:
2)the art of breaking :rock:
3)rawkfist :rock:
User avatar
Itachi
 
Posts: 54
Joined: Sat Dec 17, 2005 2:55 pm
Location: Louisville (in my on little world)

Postby glitch1501 » Tue Dec 20, 2005 11:34 am

why what?

Glitch's Photostream


He wants them to learn to walk and must therefore take away His hand; and if only the will to walk is really there, He is pleased even with their stumbles.

Image

Healing hands of God have mercy on our unclean souls
once again. Jesus Christ, Light of the World, burning
bright within our hearts forever. Freedom means love
without condition, without beginning or an end. Here's
my heart, let it be forever Yours, only You can make
every new day seem so new.
Every New Day - On Distant Shores - Five Iron Frenzy

Nail pierced hands they run with blood
A splitting brow forced by the thorns
His face is writhing with the pain yet it's comforting to me
Passion - Kutless
:thumb:
Image
User avatar
glitch1501
 
Posts: 2177
Joined: Mon Oct 20, 2003 6:50 pm
Location: the debris section

Postby Slater » Tue Dec 20, 2005 3:47 pm

hmm... that might be a bit difficult, though don't take my word for it so readily. What's the site, may I take a look?
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Warrior4Christ » Tue Dec 20, 2005 5:10 pm

I've used cookies before using a Java Servlet and Tomcat... I'm pretty sure you can do the same sort of thing with inline Java code...

Here's how I did it (added stars for emphasis of relevant parts):

Code: Select all
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;

// ProcessNameExt

public class ProcessNameExt extends HttpServlet
{
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    // get the name parameter from URL rewriting
    String name = request.getParameter(LoanCalcExt.nameTag);

    // make a cookie to store the name so it can be
    // accessed in other parts without URL rewriting.
[b]****Cookie cookie = new Cookie(LoanCalcExt.nameTag, name);****
****response.addCookie(cookie);****[/b]

    // dynamically write the html file...
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Thank you for registering.</title>");
    out.println("</head>");
    out.println("<body bgcolor=#FFFFFF>");
    out.println("<h3>Thank you for registering.</h3>");
    out.println("Please click <a href=\"LoanCalcExt\">here</a> to use the loan calculator.");
    out.println("</body>");
    out.println("</html>");
  }

  // if the method was POST, then make it do the same thing as GET.
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    doGet(request, response);
  }
}


Code: Select all
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;

// LoanCalcExt

public class LoanCalcExt extends HttpServlet
{
  public final static String sizeTag = "principal";
  public final static String interestRateTag = "rate";
  public final static String durationTag = "duration";
  public final static String nameTag = "username";

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    // get the cookies stored in the HTTP header
[b]****Cookie[] cookies = request.getCookies();****[/b]
    String name = null;  // make the default null, so we can tell if a cookie name was given

    // search through the cookies for the name cookie
    [b]******************************
    for(int index = 0; index < cookies.length; index++)
    {
      if(cookies[index].getName().equals(nameTag))
      {
        // found it, set the name variable to it
        name = cookies[index].getValue();
        break;
      }
    }
    ********************************[/b]
    // dynamically write html file...
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Loan Calculator</title>");
    out.println("</head>");
    out.println("<body bgcolor=#FFFFFF>");
    // if no name cookie was found, make the user register first
    if(name == null)
    {
      out.println("<h1>Bank loan calculator - Please Register</h1>");
      out.println("You must register to use this service.
");
      out.println("Please enter your name in the following form.
");
      out.println("<form method=GET action=\"ProcessNameExt\">");
      out.println("Your name: <input type=text size=25 name=" + nameTag + ">
");
      out.println("<input type=submit>
");
      out.println("</form>");
    }
    // if the user has a name cookie, then carry on with the input form
    else
    {
      out.println("<h1>Bank loan calculator</h1>");
      out.println("<h2>Greetings " + name + "</h2>");
      out.println("Work out how much interest you would have to pay on a house loan.
");
      out.println("Enter the size of the loan, the annual interest rate and the number of years the loan is for.
");
      out.println("<form method=GET action=\"CalcInterestExt\">");
      out.println("Size of loan (in dollars): <input type=text size=20 name=" + sizeTag + ">
");
      out.println("Annual Interest Rate(%): <input type=text size=20 name=" + interestRateTag + ">
");
      out.println("Duration of loan (in years): <input type=text size=20 name=" + durationTag + ">
");
      out.println("<input type=submit>
");
      out.println("</form>");
      out.println("<p>Press the submit button to calculate your result.</p>");
      out.println("<p>If your name is not correct, then please enter your name in the following form:</p>");
      out.println("<form method=GET action=\"ProcessNameExt\">");
      out.println("Your name: <input type=text size=25 name=" + nameTag + ">
");
      out.println("<input type=submit>
");
      out.println("</form>");
    }
    out.println("</body>");
    out.println("</html>");
  }

  // if the method was POST, then make it do the same thing as GET.
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    doGet(request, response);
  }
}



...though on second thoughts, you want to store a cookie attached to an URL rather than a previous page (as done here)... so you probably use a different method.
Everywhere like such as, and MOES.

"Expect great things from God; attempt great things for God." - William Carey
User avatar
Warrior4Christ
 
Posts: 2045
Joined: Sat Aug 20, 2005 8:10 pm
Location: Carefully place an additional prawn on the barbecue

Postby Slater » Tue Dec 20, 2005 5:54 pm

hmm... Yeah, listen to W4C... he knows more about cookies than I do XD
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Mithrandir » Thu Dec 22, 2005 11:00 am

Huh? That's WAY more complicated than a javascript set cookie function could EVER be. IMHO.

In 5 seconds I found the following on google:
Code: Select all
 function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}



Go here for the complete text:
http://www.javascripter.net/faq/settinga.htm

For information on how to read and set cookies, you can find it here:
http://www.netspade.com/articles/2005/11/16/javascript-cookies/
User avatar
Mithrandir
 
Posts: 11071
Joined: Fri Jun 27, 2003 12:00 pm
Location: You will be baked. And then there will be cake.


Return to Computing and Links

Who is online

Users browsing this forum: No registered users and 194 guests