将数据从前端推送到中间层

时间:2017-05-06 19:26:40

标签: java html jsp

应用程序根据给定条件接受firstName和lastName。

  1. 仅搜索firstName(禁用lastName字段)
  2. 仅搜索lastName(禁用firstName字段)
  3. 按firstName或lastName搜索(均已启用)
  4. 按firstName和lastName搜索(均已启用)
  5. 对于条件1和2,我可以在JSP中获取数据并填充业务对象,将其推送到服务层以查询结果,但问题是当两个输入字段都有数据时如何获取条件3和4的数据。 / p>

    逻辑应该是什么? JSP代码应该是什么?

    <body>
    
    
        <%
            String FirstName = request.getParameter("firstName");
            String LastName = request.getParameter("lastName");
            String id = request.getParameter("id");
        //  int id = Integer.parseInt(request.getParameter("id"));
            UserBo bo = new UserBo();
            bo.setId(id);
        //  bo.setId(new Integer(id).toString());
            bo.setFirstName(FirstName);
            bo.setLastName(LastName);
            UserService userService = new UserService();
            int i = userService.insertUser(bo);
    
    
            if (i == 1) {
        %>
    
        Data Inserted Successfully for First Name: ${param.firstName}
        <br> Last Name: ${param.lastName}
        <br> ID: ${param.id}
    
        <%
            } else {
    
    
            }
        %>
    
    </body>
    

    <html>
    <body>
    
    <form action="../jsp/searchActorData.jsp" id=id >
    <br>
    <br>
    <h3>Search by:  
    
    <select id="menu" name ="nameField"> </h3> 
                 <option value="null" selected="selected" >--- Please Select---</option>
                <option> Only FirstName </option>
                <option> Only LastName  </option>
                <option> Or </option>
                <option> And </option>
                </select>
    
    <br><br>
    First Name <input id="first" type="text" name="firstName"/>
    Last Name <input id="last" type="text" name="lastName"/>
    <br><br>
    <input type="submit"/>
    <input type="reset"/>
    
    </form>
    
    <script type="text/javascript">
    var menu = document.getElementById('menu');
    var first = document.getElementById('first');
    var last = document.getElementById('last');
    
    menu.onchange = function(){
    
         var enableFirst = false, enableLast = false;
        switch(menu.options.selectedIndex){
            case 0:
                enableFirst = false;
                enableLast =  false;
                break;
            case 1:
                enableFirst = true;
                enableLast =  false;
                break;
            case 2:
                enableFirst = false;
                enableLast =  true;
                break;
            case 3:
                enableFirst = true;
                enableLast =  true;
                break;
            case 4:
                enableFirst = true;
                enableLast = true;
    
            default:
                enableFirst = false;
                enableLast =  false;
                break;
    
        }
        first.disabled = !enableFirst;
        last.disabled = !enableLast;
    
    
    }
    
    </script>
    
    </body>
    </html>
    

0 个答案:

没有答案