由于在 jsp 文件中使用双引号而导致的简单错误

发布于 2024-11-17 11:25:20 字数 547 浏览 0 评论 0原文

我的 Web 应用程序的 JSP 文件中有以下代码行出现错误:

<jsp:setProperty name="db" property="userName" value="<%=request.getParameter("userName")%>"/>

我收到的错误消息是:

org.apache.jasper.JasperException: /loginbean.jsp(6,59) 属性值 request.getParameter("用户名") 是 用 " 引用,必须转义 当在值内使用时

我在某些网站上读到的是像 ' (单引号)或 " (双引号)这样的字符需要以转义序列作为前缀 \ (反斜杠),如果要使用它们,

但是,当我尝试在双引号(用户名周围)添加反斜杠前缀时,我立即收到以下错误 - “非法字符 \92- 未闭合字符串”。字面意思”

我该如何解决这个问题?

I have the following line of code in a JSP File in my web app that is giving an error:

<jsp:setProperty name="db" property="userName" value="<%=request.getParameter("userName")%>"/>

The error message that I get is:

org.apache.jasper.JasperException:
/loginbean.jsp(6,59) Attribute value
request.getParameter("userName") is
quoted with " which must be escaped
when used within the value

What I read on some sites is that characters like ' (single quote) or " (double quote) need to be prefixed with an escape sequence \ (backslash) if they are to be used.

However, when I try and prefix the double quotes (around the word userName) with backslash, I immediately get the following error- "Illegal Character \92- Unclosed String Literal"

How do I resolve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

土豪 2024-11-24 11:25:20

您应该在 value 参数上使用单引号,即:

value='<%=request.getParameter("userName")%>'

或将 org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING 参数设置为 false如此处所述:

http://blogs.sourceallies.com/2009/10/strict-quote-escaping-in-tomcat/

You should use single quotes on the value parameter, ie:

value='<%=request.getParameter("userName")%>'

or set the org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING parameter to false as described here:

http://blogs.sourceallies.com/2009/10/strict-quote-escaping-in-tomcat/

稀香 2024-11-24 11:25:20

如果您使用的是 Tomcat 8.5+,则属性 org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false
不会被承认。

通过在 块中添加以下内容,我能够在 {TOMCAT_ROOT}/conf/web.xml 中成功设置该属性:

<init-param>
    <param-name>strictQuoteEscaping</param-name>
    <param-value>false</param-value>
</init-param>

If you are using Tomcat 8.5+, the property org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false
will not be acknowledged.

I was able to set the property successfully in {TOMCAT_ROOT}/conf/web.xml by adding the following within the <servlet> block:

<init-param>
    <param-name>strictQuoteEscaping</param-name>
    <param-value>false</param-value>
</init-param>
╰つ倒转 2024-11-24 11:25:20

如果您不想修改 JSP,只需

org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false

{TOMCAT_ROOT}/conf/catalina.properties 文件中 设置:效果就像一个魅力!

来自这里

If you don't want to modify your JSPs, just set:

org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false

in your {TOMCAT_ROOT}/conf/catalina.properties file. Works like a charm!

Kudos from here.

数理化全能战士 2024-11-24 11:25:20

这可以通过 IDE Regexp Replace 来修复:

(<\w+:(?:[^>]|<%=[^%]+%>)+=)"([^<"]*<%=[^%]*"[^%]*%>[^"]*)"

对于替换文本,输入:

$1'$2'

This can be fixed with a IDE Regexp Replace:

(<\w+:(?:[^>]|<%=[^%]+%>)+=)"([^<"]*<%=[^%]*"[^%]*%>[^"]*)"

For the replacement text, enter:

$1'$2'

我早已燃尽 2024-11-24 11:25:20

该示例看起来像 XSS 示例!这是一个安全漏洞。
我建议放置一个 html 编码库,例如 c:out 标记或 http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/Encoder.html#encodeForHTMLAttribute%28java.lang.String%29

我还建议从经过身份验证的会话中获取用户名,如果可能的话,不要形成请求参数(除非这只是登录/注册表单!)

The example looks like a XSS example! This is a security vulnerability.
I suggest to put in place a html encoding library like c:out tag or http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/Encoder.html#encodeForHTMLAttribute%28java.lang.String%29

I also suggest to take the userName from an authenticated session and not form the request param if possible (unless this is a login/registration form only!)

感情旳空白 2024-11-24 11:25:20

如果使用 " 作为 scriplet 分隔符,则不能在 getParameter 中使用 some 作为属性分隔符。因此将 scriptlet 的分隔符更改为 '。作为标记参数,我认为不会有问题。否则替换 :

value ="<%=request.getParameter("用户名")%>"/>

通过:

value='<%=request.getParameter("用户名")%>'/>;

if you use a " as scriplet delimeter, you can't use the some as a property delimiter in getParameter. So change the delimeter of scriptlet by '.As it tag parameter, I think there 'll be no problem. Otherwise replace :

value="<%=request.getParameter("userName")%>"/>

by :

value='<%=request.getParameter("userName")%>'/>

蓝眸 2024-11-24 11:25:20

我的情况是在项目构建期间使用 Jasper JSP 验证阶段。

从 Tomcat 8 开始,有一个新属性 strictQuoteEscaping Ant 任务和开关 -no-strictQuoteEscaping 用于运行 org.apache. jasper.JspC 从命令行。

I case Jasper JSP validation phase is used during project build.

Since Tomcat 8 there is a new attribute strictQuoteEscaping for Ant task and a switch -no-strictQuoteEscaping for running org.apache.jasper.JspC from command line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文