which must be escaped when used within the value 问题解决方法

本文介绍了解决JSP页面中因Tomcat版本升级而导致的双引号逃逸错误的方法,包括调整Tomcat配置及使用转义字符等解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

访问JSP时,报错:Attribute value is quoted with " which must be escaped when used within the value 。相信很多人都遇到过,以下结合本人查资料与亲自实践得到的结论。

有不对的地方还请指教。

 

1):错误常发生的位置 value="<%=""+request.getAttribute("name")%>"  

2):错误产生的原因,是因为tomcat版本升级后(6.0以后),对双引号的处理机制引起的,如果出现双引号包含双引号的情况,就可能会出现这个错误。

3):解决办法有好多种,大多数网上的意见是改为value=‘<%=""+request.getAttribute("name")%>’ 这样确实可以解决这个报错,可能无法完全解决问题,比如项目中有很多地方以前都用的是双引号,修改起来会非常麻烦,还容易出错。

         查看tomact文档有一段话这样描述的“Iffalsethe requirements for escaping quotes in JSP attributes will be relaxed so that an unescaped quote will not cause an error.

If not specified, the specification compliant default oftruewill be used.”    这个描述针对的是tomact的org.apache.jasper.compiler. Parser.STRICT_QUOTE_ESCAPING属性。

       如此一来,我们知道只要在tomcat启动时将这个属性设为false就可以解决这个问题。

       那么怎么将这个属性设置到tomcat的system属性中呢,有至少两个办法:

      一种是利用tomcat启动的执行脚本,在执行过程中调用setenv.sh,在其中设置环境变量,如:JAVA_OPTS=%JAVA_OPTS%: -Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false

     另一种是找到conf/catalina.properties文件,在最后添加org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false 即可。

方法 3:使用转义字符("\")

1<jsp:include page="split_page.jsp">
2    <jsp:param name="jspUrl" value="<%=jspUrl%>" />
3    <jsp:param name="category" value="<%=equest.getParameter(\"category\")%>" />
4    <jsp:param name="searchFlag" value="T" />
5</jsp:include>


### Shell Scripting or Shell Commands Shell scripting is a fundamental aspect of Unix-like operating systems, including Linux and macOS. It involves writing scripts that automate repetitive tasks, manage system resources, and interact with other programs. The shell itself serves as both an interactive command interpreter and a scripting language[^1]. #### Special Meanings of Parentheses in Shell Scripts Parentheses `(` and `)` have specific meanings in shell scripting, particularly in bash. They are used for creating subshells, grouping commands, and defining arrays. For example: - **Subshells**: `(command1; command2)` creates a subshell where the commands inside the parentheses are executed in isolation from the main shell environment. - **Command Grouping**: `{ command1; command2; }` groups commands together but does not create a subshell. Note the semicolon after each command and the braces. - **Array Definitions**: `array=(value1 value2 value3)` defines an array named `array` with three elements. When using parentheses literally in commands like `tcpdump`, they must be escaped with a backslash (`\`) so the shell interprets them as literal characters rather than part of its syntax[^1]. ```bash tcpdump \( host 192.168.1.1 \) ``` #### External Programs in Shell Scripts Many useful commands within shell scripts are external Unix utilities rather than built-in shell commands. Some common external utilities include: - `tr`: Translating or squeezing characters. - `grep`: Searching files for lines that match patterns. - `expr`: Evaluating expressions. - `cut`: Removing sections from each line of files. Built-in commands such as `echo`, `test`, and `which` are often directly integrated into the shell, providing faster execution without invoking an external process[^2]. #### Identifying Directories and Executables The `ls` command can help identify directories and executable programs. By using the `-F` flag, `ls` appends a `/` to directory names and a `*` to executable program names. This feature aids in quickly distinguishing between different types of files when navigating or scripting in the shell[^3]. ```bash ls -F /path/to/directory ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值