Java表单验证

时间:2013-09-02 13:41:47

标签: java spring

我有一个有搜索框的网站。我想在用户点击搜索而不输入任何文字时验证搜索框。他应该收到一条错误消息,但我收到以下错误:

  

java.lang.IllegalStateException:BindingResult和bean名称'searchForm'的普通目标对象都不可用作请求属性

我的表格如下:

<blc:form th:action="@{/search}" th:object="${searchForm}"  method="POST">
    <input type="search" class="search" name="q" th:value="${originalQuery}" />
        <span th:if="${#fields.hasErrors('searchText')}" th:errors="*{searchText}">dddd</span>
    <input type="submit" id="search_button" value="go" />
</blc:form>

我的控制器如下:

@Controller
@RequestMapping("/search")
public class SearchController extends Mysearchcontroller {
    @RequestMapping("")
    public String search(HttpServletRequest request, HttpServletResponse response,
            @RequestParam(required = false) String q,@ModelAttribute("mysearchForm") Mysearchform mysearchForm,BindingResult errors,Model model) throws ServletException, IOException, ServiceException {
        return search3(model, request,response, q ,errors);
    }
}

1 个答案:

答案 0 :(得分:-2)