如何在刷新jsp页面后单击单选按钮选择单选按钮

时间:2016-04-18 05:23:40

标签: javascript jquery html spring

我有两个单选按钮,我想点击单选按钮后刷新页面我怎么能这样做,我想太多但不能这样做,我需要你的帮助。

<script>
 $(document).ready(function() {
        $(document).on('click', 'input[type=radio][name=test1]', function() 
            { 
            var clicked = localStorage['clicked'];
           $('.' + related_class).prop('disabled', false); 
          $('input[type=radio][name=test1]').not(':checked').each(function()
             { var other_class = $(this).val(); 
          $('.' + other_class).prop('disabled', true); 
        }); 
      });
   });    
 </script>

这是员工的第一个单选按钮

<td>
    <label for="radio1">
        <input type="radio" name="test1" value="radio1" /><b>Employee</b>
    </label>    
    Select Employee 
        <input type="image" img  src="resources/image/search.png"name="for_radio1[]" class="radio1"  disabled="true" onclick="openWindow()"/> 
</td>

这是角色的另一个单选按钮。

<td>
    <form action="/Submitrole" method="post" model="command">
        <label for="radio2"><input type="radio" name="test1" value="radio2"/>Role </label><br>
                        Select Role :<select  name="roleName"  class="radio2" disabled="true" style="width: 80px;">
                                        <c:forEach items="${listRole}" var="role">
                                            <option value="${role.roleName}">
                                                    <c:out value="${role.roleName}" />
                                            </option>
                                        </c:forEach>
                                    </select>
        <input type="submit" value ="Check">
    </form>
</td>

控制器。

 @RequestMapping(value = "/compplan", method = RequestMethod.GET)
public ModelAndView listRules(ModelMap model, HttpServletRequest request,HttpSession session, SessionStatus status) {

    roleApi.listOfRoles();
    ruleApi.listOfRules();

    model.addAttribute("listRole", roleApi.listOfRoles());
    model.addAttribute("listRules", ruleApi.listOfRules());
    RoleUI object = (RoleUI) request.getSession().getAttribute("roleName");
    if (object != null ) {
        RuleAssignment rAssdtail = ruleAssApi.searchAssignedRule(object.getRoleName());
        List<RuleAssignmentDetails> ptr1 = rAssdtail.getRuleAssignmentDetails();
        ArrayList<Rule> rl1 = new ArrayList<Rule>();
        List<RuleParameter> parameterList = new ArrayList<RuleParameter>();
        Iterator<RuleAssignmentDetails> it1 = ptr1.iterator();
        while (it1.hasNext()) {
            RuleAssignmentDetails rp = (RuleAssignmentDetails) it1.next();
            Rule r1 = rp.getRule();
            List<RuleParameter> ptr2 = r1.getRuleParameter();
            Iterator it = ptr2.iterator();
            while (it.hasNext()) {
                RuleParameter r2 = (RuleParameter) it.next();
                parameterList.add(r2);
            }
            rl1.add(r1);
        }       
        model.addAttribute("List2", rl1);
        status.setComplete();
        session.removeAttribute("roleName");
       return new ModelAndView("CompPlan"); 
    }

    EmployeeUI object1 = (EmployeeUI) request.getSession().getAttribute("EmployeeName");
    if(object1 != null) {

        RuleAssignment rAssdtail = ruleAssApi.searchAssignedRule(object1.getEmployeeName());
        List<RuleAssignmentDetails> ptr1 = rAssdtail.getRuleAssignmentDetails();
        ArrayList<RuleAssignmentDetails> ruleList1 = new ArrayList<RuleAssignmentDetails>();
        ArrayList<Rule> rl1 = new ArrayList<Rule>();
        List<RuleParameter> parameterList = new ArrayList<RuleParameter>();
        Iterator<RuleAssignmentDetails> it1 = ptr1.iterator();
        while (it1.hasNext()) {

            RuleAssignmentDetails rp = (RuleAssignmentDetails) it1.next();
            Rule r1 = rp.getRule();
            List<RuleParameter> ptr2 = r1.getRuleParameter();

            Iterator it = ptr2.iterator();
            while (it.hasNext()) {
                RuleParameter r = (RuleParameter) it.next();        
                parameterList.add(r);
            }
            rl1.add(r1);
        }
        model.addAttribute("List2", rl1);
        status.setComplete();
        session.removeAttribute("EmployeeName");
        request.getParameter("test1");
        return new ModelAndView("CompPlan");    
    }   
return new ModelAndView("CompPlan");

}

我怎么能这样做,请帮助我。

谢谢。

2 个答案:

答案 0 :(得分:1)

您可以使用location.reload(); 更多信息here

答案 1 :(得分:0)

尝试在为该按钮发生单击事件时调用此类函数

<script> 
    function refreshPage {  
        window.location.reload();
    }
</script>

编辑: 选择无线电后,在服务器代码中获取该值,并将其作为请求参数或属性发送到jsp。因此,当重新加载jsp时,您已经选择了两个值。在你的jsp的任何一点你都可以跟踪该值为

request.getParameter("name")

你可以选择收音机。

编辑:

嗯,我知道你正在使用任何类型的MVC模式。假设您有一个servlet(或在JSP重新加载后重定向到的任何控制器),您可以获取单选按钮值并存储在变量中。类似的东西:

String rValue = request.getParameter("radioButtonName");

之后,您只需将servlet的响应发送到同一个JSP,但包括单选按钮的值。你有2个选择

将值作为resquest参数发送:

String yourJsp = "/theJsp.jsp?radioValue=" + rValue;
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(yourJsp)dispatcher.forward(request,response);

获取JSP中的值:

<%=request.getParameter("radioValue")>

或者将值作为resquest属性发送到servlet(控制器)中(我更喜欢这个):

...
request.setAttribute("radioValue", rValue);
...

获取JSP中的值:

<%= request.getAttribute("radioValue")>

最后,如何设置所选单选按钮的值?尝试像

这样的东西
<input type="radio" name="test1" value="radio1" <%= request.getAttribute("radioValue").equals("radio1")?"checked":""/><b>Employee</b>

关键是你可以了解所有这些(考虑到这是一个简短的描述)。我现在无法测试,但我希望它有效。