开发者

Set the value of the select box using cookie value in struts1

Hi friends,

I am trying to set the value of the select box using the cookies value (i want every time same value that i select the first time until i am not made any changes to it).

I am working with the struts1.

Here is my JSP:

<html:select property="employee" >
    <html:option value="">--- select one ---</html开发者_开发百科:option>
    <html:optionsCollection name="empList" value="id" label="name" />
</html:select>

and in the action class I have the following:

String empStr; // value sent from the form

if (CookieUtils.getCookie(request, "employee") == null) {
    CookieUtils.setCookieValue(response, employee,
                    empStr, 60 * 60);
}else{
   if(empStr!=null && !empStr.equals(""))
     CookieUtils.setCookieValue(response, "employee",
                        empStr, 60 * 60);
   CookieUtils.getCookie(request, "employee");
}

Please help me.


The simple way is by using getParameter method of request object. Suppose the name of the checkbox is "mycheckbox" then use following code: String value = request.getParameter("mycheckbox");


At the time of debugging the code i found that i miss the struts 1 main property i.e i need to give all the information to the form (set the values that you want on the request). So after setting the values in the action class for the form solves my problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜