java 在 JSP 中,path 和 value 属性在 input 标签中做什么,表单前缀如何影响它们?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4151096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:02:48  来源:igfitidea点击:

In JSP, what do the path and value attribute do within the input tag, and how does the form prefix affect them?

javajspattributesinput

提问by Danny

Just wanted a clear answer for a direct question -- google results have been all over the place or don't address the combos you'll see below.

只是想要一个直接问题的明确答案 - 谷歌搜索结果到处都是,或者没有解决您将在下面看到的组合。

I'm generally a JSP newbie and have been screwing around with the following code.

我通常是一个 JSP 新手,并且一直在使用以下代码。

<form:input id="theId" path="path.copied.directly.fromSomewhereElse"
    cssClass="contentTextInput" cssStyle="width: 229px" />

When I put that into my JSP page and load my website, it works fine and looks as my cssClass defines it. Then I start messing with it because I want it to display a default value.

当我将它放入我的 JSP 页面并加载我的网站时,它工作正常并且看起来就像我的 cssClass 定义的那样。然后我开始弄乱它,因为我希望它显示一个默认

<form:input id="theId" path="path.copied.directly.fromSomewhereElse"
    value="blah" cssClass="contentTextInput" cssStyle="width: 229px" />

Suddenly, HTTP 500, an org.apache.jasper.JasperException! So I decide to remove the pathaltogether, while leaving in the value. This is just step 1 in something I know works because of prior experience. The code is now:

突然,HTTP 500,一个 org.apache.jasper.JasperException!所以我决定完全删除路径,同时保留值。由于先前的经验,这只是我知道可行的事情的第 1 步。现在的代码是:

<form:input id="theId" value="someClass.valueIWantAsDefault" 
    cssClass="contentTextInput" cssStyle="width: 229px" />

That actually throws an exception, too -- but then I remove the form prefix and it works-- mostly. You see, the cssClass's effects are now gone; it looks like a regular, unaffected input textbox. Here's the code so far.

这实际上也引发了一个异常——但随后我删除了表单前缀并且它起作用了——主要是。你看,cssClass 的效果现在不见了;它看起来像一个普通的、不受影响的输入文本框。这是到目前为止的代码。

<input id="theId" value="someClass.valueIWantAsDefault" 
    cssClass="contentTextInput" cssStyle="width: 229px" />

What exactly do these attributes (and prefix) do that makes this mix-and-match work?

这些属性(和前缀)究竟做了什么使这种混合匹配起作用?

回答by Asaph

I'm guessing you're dealing with a jsp page that relies on a JSP custom tag library that's part of the Spring Framework. Here are the docs for the <form:input>tag. valueis not a valid attribute for this custom tag as you can see in the docs link I provided above. When you remove the form:, you're turning the tag into a plain old HTML <input>tag which is why your error is going away at that point. It's also why your css stops working. cssClassis not the correct attribute for the HTML <input>tag. It's simply class. They called it cssClassin the jsp custom tag lib most likely to avoid a lower level collision with the Object.getClass()method (long story, just take my word for it).

我猜您正在处理一个依赖 JSP 自定义标记库的 jsp 页面,该库是 Spring 框架的一部分。这是<form:input>标签的文档。value不是此自定义标记的有效属性,如您在我上面提供的文档链接中所见。当您删除 时,您会将form:标签变成一个普通的旧 HTML<input>标签,这就是为什么您的错误在那一点消失的原因。这也是您的 css 停止工作的原因。cssClass不是 HTML<input>标记的正确属性。简直了class。他们cssClass在 jsp 自定义标签库中调用它最有可能避免与该Object.getClass()方法发生较低级别的冲突(长话短说,相信我的话)。