java - 根据 TLD 获取标签 [form] 的属性 [modelAttribute] 无效

标签 java html spring spring-mvc jsp

我对 Spring 完全陌生,并且收到错误“根据 TLD 获取标签 [form] 的属性 [modelAttribute] 无效” 运行下面的代码时。

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Personal Info Page</title>
</head>
<body>
<center><h1>Personal Info Page</h1></center>
<form:form  method="post" action="/user-web/processuserregistration.do" modelAttribute="user" >
      <table>
          <tr>
              <td>First Name:</td>
              <td><form:input path="firstName"/></td>
          </tr>
          <tr>
              <td>Last Name:</td>
              <td><form:input path="lasttName"/></td>
          </tr>

          <tr>
              <td>Middle Name:</td>
              <td><form:input path="middleName"/></td>
          </tr>

          <tr>
              <td colspan="2">
                  <input type="submit" value="Save Changes" />
              </td>
          </tr>
      </table>

</form:form>
</body>
</html>

运行这段代码后,我收到以下错误:

Oct 07, 2019 9:31:44 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/user-web] threw exception [/jsp/person.jsp (line: [9], column: [0]) Attribute [modelAttribute] invalid for tag [form] according to TLD] with root cause
org.apache.jasper.JasperException: /jsp/person.jsp (line: [9], column: [0]) Attribute [modelAttribute] invalid for tag [form] according to TLD
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:292)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:115)

我可以采取什么措施来解决该错误吗? 我对 Spring 完全陌生

最佳答案

嗯,

我要先声明,我不是 JSP 开发人员,但我整天都在使用 Java 和 HTML/CSS/JS。我还没有编译过 JSP 页面,但我知道它只是带有一些脚本的 HTML。我可以帮助您的只是提醒您,与 HTML 一起使用时“属性”一词指的是 HTML 元素内部的“类似赋值”的内容。例如,您正在使用 HTML 'form' 元素。

根据 w3schools.com(我在编码时每天至少引用一次),HTML 表单元素允许具有以下属性... 下一个“评论 block ”内的文本已从以下链接逐字复制: https://www.w3schools.com/html/html_forms.asp

The Action Attribute The action attribute defines the action to be performed when the form is submitted. Normally, the form data is sent to a web page on the server when the user clicks on the submit button. In the example above, the form data is sent to a page on the server called "/action_page.php". This page contains a server-side script that handles the form data:

<form action="/action_page.php">

If the action attribute is omitted, the action is set to the current page.

The Target Attribute The target attribute specifies if the submitted result will open in a new browser tab, a frame, or in the current window. The default value is "_self" which means the form will be submitted in the current window. To make the form result open in a new browser tab, use the value "_blank"... Example:

<form action="/action_page.php" target="_blank">

Other legal values are "_parent", "_top", or a name representing the name of an iframe.

The Method Attribute The method attribute specifies the HTTP method (GET or POST) to be used when submitting the form data:

<form action="/action_page.php" method="get"> or

<form action="/action_page.php" method="post">

1: https://www.w3schools.com/html/html_forms.asp

重要的一点是:HTML 表单可能没有您添加的“modelAttribute='user'”行...

<form:form  method="post" action="/user-web/processuserregistration.do" modelAttribute="user" >

根据 Oracle 文档,TLD 是标记库描述符 - 它用于 JSP 编程。这是 Oracle TLD 页面的链接。再次,我很抱歉作为非 JSP 人员发帖...但这也许会有所帮助:)

https://docs.oracle.com/cd/E17904_01/web.1111/e13722/tld.htm#TAGLB120

关于java - 根据 TLD 获取标签 [form] 的属性 [modelAttribute] 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58280293/

相关文章:

java - ORMLite 外国成员(member)更新

java - GWT Java 电子邮件 - java.io.UnsupportedEncodingException : text/html

java - 如何只获取目录中的最新文件名

html - Twitter 卡片预览无法获取我的图像

html - Bootstrap 4 - 使 div 变为正方形时内容会粘在 div 的底部

spring - 如何配置 glassfish 以使用应用程序托管实体管理器?

java - 我的 pom.xml 中有 javax.inject,spring 会自动使用它吗?

java - 如何退出循环或onClick(android)?

spring - 如何以编程方式在 Cucumber 中设置 Spring 配置文件

jquery - Twitter Bootstrap 3 中的多个固定顶部导航栏标题无法正常工作?