pass a string from the jsp to the servlet
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   tyris_d
Posted On:   Friday, April 20, 2001 12:46 AM

hi all, i'm new to jsp i want to pass from a jsp a string to a servlet with a cookie. i've seen examples in sun web site, so i made my class like they explained : public void getCookie (HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { String value=""; Cookie[] cookies = request.getCookies(); response.setContentType("text/html"); PrintWriter out = response.getWriter(); if (cookies != null) { for (int i=0; i < cookies.length; i++) { if (cookies.getName().equals("MyCookie")) { value = cookies.getValue(); break; } } }    More>>

hi all,
i'm new to jsp
i want to pass from a jsp a string to a servlet with a cookie.
i've seen examples in sun web site, so i made my class like they explained :


			
public void getCookie (HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
String value="";
Cookie[] cookies = request.getCookies();
response.setContentType("text/html");
PrintWriter out = response.getWriter();
if (cookies != null) {
for (int i=0; i < cookies.length; i++) {
if (cookies.getName().equals("MyCookie")) {
value = cookies.getValue();
break;
}
}
}
out.println(" " + value + " ");

}


but i'm a bit lost for my jsp... i guess i should use a post method, but i don't know how.. what i begun to make is :


			


<%
Cookie info = null;
info = new Cookie ("MyCookie", "toto");
info.setPath("/");
info.setMaxAge(10*24*60*60);
response.addCookie(info);
%>


.... (submit button and form)




i think i don't use the correct method. in fact i don't know what it should do : create the cookie, and then ? or is there way to send them to the servlet ?



as you have noticed i put ACTION="????" because i don't know what to call.. my method getCookie ? nothing ?



an other question is that i have read i need to put those parameters : HttpServletRequest request,HttpServletResponse response but i don't even know why and what they are....

I must say also that for the moment i can't use BEANS, only servlets, so can i anyway use action ?



i'm sorry for my coarse english.



Best regards ,
Elise    <<Less

Re: pass a string from the jsp to the servlet

Posted By:   Vasu_Devan  
Posted On:   Friday, April 20, 2001 04:12 AM

You probably need a crash course on servlets. A good one is there at

http://developer.java.sun.com/developer/onlineTraining/Servlets/Fundamentals/
About | Sitemap | Contact