HTML 未通过验证
下面的行没有在我的应用程序中通过验证。 Netbeans 中的错误是...
元素“a”上的属性 href 的错误值“/content/edit”:PATH 中的 WHITESPACE
<a href="<%=request.getAttribute("urlPrefix")%>/content/edit">Add Content</a>
运行时错误是:
org.apache.jasper。 JasperException: /base.jsp(9,25) PWC6213: 需要引号
我正在传递该值的属性。为什么我在传递值时会收到此错误?
The below line is not passing validation in my application. The error is in Netbeans is...
Bad value " /content/edit" for attribute href on element "a": WHITESPACE in PATH
<a href="<%=request.getAttribute("urlPrefix")%>/content/edit">Add Content</a>
The runtime error is:
org.apache.jasper.JasperException: /base.jsp(9,25) PWC6213: quote symbol expected
I am passing an attribute for this value. Why am I getting this error when I pass a value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不要在 JSP 中使用 scriptlet。使用 JSP EL:
Don't use scriptlets in JSP. Use the JSP EL:
在
urlPrefix
中使用单引号。它应该有效。Use single quotes with
urlPrefix
. It should work.试试这个:
或者更好这个:
或者更好地使用 EL:
值得一提的是针对 XSS 攻击 作为 Asaph 在他的评论中指出:
可能会成功。
如果您将其包含在 JSP 的顶部,
Try this:
or better this:
or even better use EL:
It's worth mentioning the protection against XSS attacks as Asaph pointed out in his comment:
might do the trick if you include
at the top of your JSP.
我刚刚做了一个简单的测试,下面的行没有语法错误,并且无论是否设置了 urlPrefix 属性,运行时都不会抛出异常:
根本没有语法错误。在没有设置
urlPrefix
属性的情况下,生成的 html 为:如果
urlPrefix
等于http://example.com,生成的 html 是:
这是一个快速的小型独立
test.jsp
文件来演示:您可以删除第一行来测试
null
情况。因此,我们已经证明您发布的涉嫌违规行实际上并没有问题。一些可能性:
I've just done a simple test and the following line has no syntax error and runs without throwing an exception whether the
urlPrefix
attribute is set or not:There is no syntax error at all. In the case of there being no
urlPrefix
attribute set, the resulting html is:In the case of
urlPrefix
being equal tohttp://example.com
, the resulting html is:Here is a quick little standalone
test.jsp
file to demonstrate:You can remove the first line to test the
null
case.So we've demonstrated that the line you posted as the alleged offending line is not actually problematic. Some possibilities: