This is a cookie and i do create them for your good need that u dont have to remember your settings.
public class CookiesGetting extends HttpServlet {
/** Initializes the servlet.
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/** Destroys the servlet.
*/
public void destroy() {
}
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Cookie [] allCookies = request.getCookies();//call the array of all cookies
String CName1 = "";
String CName2 = "";
String CValue1 = "";
String CValue2 = "";
if(allCookies!=null)//Loop through the array of cookies to get the one of interest
{
for(int i=0; i<allCookies.length; i++)
{
Cookie temp = allCookies;
if(temp.getName().equals("Username"))
{
CName1 = temp.getName();
CValue1 = temp.getValue();
}
else if(temp.getName().equals("password"))
{
CName2 = temp.getName();
CValue2 = temp.getValue();
}
}
}
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h3>Cookies from client</h3>" +
"<ul><li>Cookies Name1: "+CName1+
"<li>Cookies Value1: "+CValue1+
"<ul><li>Cookies Name2:"+CName2+
"<li>Cookies Value2: "+CValue2+
"</ul>");
out.println("</body>");
out.println("</html>");
out.close();
}
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}