前台代码
(xxx.html)
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form id="iform" th:action="@{/list}" th:method="post" th:object="${user}"><input type="text" th:field="*{name}"/>
<input type="submit"></form>
</body>
</html>
后台代码
package com.example.demo;import javax.servlet.http.HttpServletRequest;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;import com.example.bean.user;@Controller
public class Test { @RequestMapping("/test")
public String login(Model model) {
return "xxx";
}
@RequestMapping("/list")
public String user(@ModelAttribute(value="user")user u, Model model,HttpServletRequest req) {
String name=u.getName();
name=req.getAttribute("name").toString();
model.addAttribute("name", name);
return "login";
}
}
数据绑定的bean
package com.example.bean;import javax.validation.constraints.NotEmpty;public class user { @NotEmpty(message="用户名不能为空")
private String name;
public String getPwd() {
return pwd;
} public void setPwd(String pwd) {
this.pwd = pwd;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} @NotEmpty(message="密码不能为空")
private String pwd;
}
报错信息
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/xxx.html]")
org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "xxx" - line 10, col 20)
org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "xxx" - line 10, col 20)
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
Neither BindingResult nor plain target object for bean name 'user' available as request attribute
ERROR 4672 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/xxx.html]")] with root cause
以上
我是通过
http://localhost:8080/test 进入到xxx.html的xxx里面有个form表单我本来是想通过表单提交数据到后台,但是现在只要进入到xxx.html就报错问题好像是出现在<input type="text" th:field="*{name}"/> 里面的th:field="*{name}" 我在网上找了很多资料但是大多数都不是针对我出现的状况麻烦大佬们指点迷津小弟万分感谢
(xxx.html)
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form id="iform" th:action="@{/list}" th:method="post" th:object="${user}"><input type="text" th:field="*{name}"/>
<input type="submit"></form>
</body>
</html>
后台代码
package com.example.demo;import javax.servlet.http.HttpServletRequest;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;import com.example.bean.user;@Controller
public class Test { @RequestMapping("/test")
public String login(Model model) {
return "xxx";
}
@RequestMapping("/list")
public String user(@ModelAttribute(value="user")user u, Model model,HttpServletRequest req) {
String name=u.getName();
name=req.getAttribute("name").toString();
model.addAttribute("name", name);
return "login";
}
}
数据绑定的bean
package com.example.bean;import javax.validation.constraints.NotEmpty;public class user { @NotEmpty(message="用户名不能为空")
private String name;
public String getPwd() {
return pwd;
} public void setPwd(String pwd) {
this.pwd = pwd;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} @NotEmpty(message="密码不能为空")
private String pwd;
}
报错信息
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/xxx.html]")
org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "xxx" - line 10, col 20)
org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "xxx" - line 10, col 20)
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
Neither BindingResult nor plain target object for bean name 'user' available as request attribute
ERROR 4672 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/xxx.html]")] with root cause
以上
我是通过
http://localhost:8080/test 进入到xxx.html的xxx里面有个form表单我本来是想通过表单提交数据到后台,但是现在只要进入到xxx.html就报错问题好像是出现在<input type="text" th:field="*{name}"/> 里面的th:field="*{name}" 我在网上找了很多资料但是大多数都不是针对我出现的状况麻烦大佬们指点迷津小弟万分感谢
解决方案 »
- 分享一个tomcat7,以xmemcached为基础的session-manager.jar(tomcat7集群session共享)
- myeclipse 8一个使用问题
- 在jsp中怎样加入 浏览 按钮
- jsp中<%= %>为null 时让它等于空
- 页面关闭时清掉session,写在哪里,请指教?
- struts表格隐藏某一列的值
- request 中的getRemoteUser()怎么使用,什么时候set的值
- 「」「」「」hibernat双向多对多怎么不能生成表呢?卡了我3天了,求救,谢谢
- 各位大虾,能否给小弟一些Jsp实例??
- 各位大侠帮帮我,怎么样记录所有用户对数据库的操作~~~在线等!
- java.nio.file.FileSystemException:另一个程序正在使用此文件,进程无法访问。
- java web实现摄像头预览功能
@RequestMapping("/test")
public String login(Model model) {
model.addAttribute("user",new user());
return "xxx";}
///
(template: "xxx" - line 10, col 20)
///
这个已经指出错误的位置了.