Add the JSTL Library as below

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

Populating a Text Box

  <input name="txtUserName" id="txtUserName" type="text" value='<c:out value="${User.userName}"></c:out>'>

Populating a Dropdown List
Type 1

 <select name="cboAge" id="cboAge">
  <c:forEach begin="20" end="60" var="i">
    <option value="${i}" <c:if test="${i == User.age}">Selected</c:if>>${i}</option>    			
  </c:forEach>
 </select>

Type 2

 <select name="cboLocation" id="cboLocation">
   <option value="Chennai">Chennai</option>
   <option value="Bangalore">Bangalore</option>
   <option value="Mumbai">Mumbai</option>
  </select>

Javascript Code

$('document').ready(function(){
  $('#cboLocation').val('<c:out value="${User.location}"></c:out>');
});

Populating Radio buttons

<input name="rdoGender" type="radio" id="rdoMale" value="1" <c:out value="${User.gender == 1?'checked':''}"></c:out>><label for="rdoMale">Male</label>
<input name="rdoGender" type="radio" id="rdoFemale" value="0" <c:out value="${User.gender == 0?'checked':''}"></c:out>><label for="rdoFemale">Female</label>

Populating Check boxes

 <input name="chkSkills" type="checkbox" id="chkJava" value="Java" <c:if test="${fn:contains(User.skills, 'Java')}">Checked</c:if>><label for="chkJava">Java</label>    	
Posted in JSP.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{	
	int lngCookieSet    = 0;
	String strCookieVal = "";
	
	String cookieName = "Name";

	Cookie[] cookies = request.getCookies();
		
	if(cookies != null && cookies.length > 0)
	{
	  for(int i=0;i<cookies.length;i++)
	  {
	    if(cookieName.equals(cookies[i].getName()))
	    {
	      lngCookieSet = 1;
	      strCookieVal = cookies[i].getValue();
	    }
	  }
	}	
		
	if(lngCookieSet == 1)
	{
	   PrintWriter prw = response.getWriter();	
	   prw.print(strCookieVal);
	}
	else
	{
	   Cookie cook = new Cookie("Name", "Mugil");
	   cook.setMaxAge(24*60*60*365);//1 Year
	   response.addCookie(cook);	
	}
}

1.We should check

cookies != null

otherwise the compiler will generate null pointer exception

2.The

new Cookie

constructor will take Cookie Name and Value as Parameter.

3.The addCookie Will add cookie to response Header to set cookie on Client Side

Posted in JSP.