【问题标题】:How do I search keyword by form and get the value?如何按表单搜索关键字并获取值?
【发布时间】:2018-01-12 00:38:54
【问题描述】:

这是我的搜索VO

public class SearchVO {

    String keyword="default";

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

}

我想在每次单击按钮时设置 SearchVO 值。

<div class="wrap bordWrap">

        <form commandName="SearchVO" id="appList" name="appList"
            action="/index2.do" method="post">

    First name: <input type="text" name="fname">
            <br>
    Last name: <input type="text" name="lname">
            <br>


            <td colspan="5"><input type="text" class="appNameID" title=""
                value="${SearchVO.keyword} " name="searchKeyword" placeholder="ID 또는 앱 이름을 입력하세요." /></td>

            <p>
                <button value="Search" onclick="formSubmit()">검색</button>
            </p>

        </form>





    </div>

我是否可以将 commnadName 设置为 searchVo 并设置搜索关键字?

我的问题是我应该从控制器中获取值吗?'

@RequestMapping("/index2.do")
public String list(ModelMap model,HttpServletRequest request, 
        @ModelAttribute("SearchVo")SearchVO searchVo){

    System.out.println("index2");
    System.out.println(searchVo.getKeyword());
    System.out.println(request.getAttribute("searchKeyword"));


    return "index";
}

【问题讨论】:

    标签: spring forms jsp


    【解决方案1】:

    您只需在 html 中使用 keyword 更改 searchKeyword 字段以匹配 SearchVO 类中的 keyword 属性的名称.这样您就可以轻松掌握它。

    如下更改以下字段名称。

     <td colspan="5"><input type="text" class="appNameID" title=""
                            value="${SearchVO.keyword} " name="keyword" placeholder="ID 또는 앱 이름을 입력하세요." /></td>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2022-06-19
      • 2023-03-23
      • 2019-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多