首先有一个类SaleEntry.class在web-inf/bean下。
<jsp:useBean id="entry" class="bean.SaleEntry"/>第一种写法:
<jsp:setProperty
name="entry"
property="itemID"
value='<%= request.getParameter("itemID")%>'/>第二种写法:
<jsp:setProperty
name="entry"
property="itemID"
value="<%= request.getParameter("itemID")%>"/>
第三种写法:
<jsp:setProperty
name="entry"
property="itemID"
value="<%= request.getParameter('itemID')%>"/>在做实验的时候第一种写法没有出现问题。但是在运行第一和第二种写法的时候,有时候能输出正确结果,有时候却有异常(重新刷新页面):org.apache.jasper.JasperException: /bean/SaleEntry.jsp(16,13) Attribute value request.getParameter("itemID") is quoted with " which must be escaped when used within the value或者:org.apache.jasper.JasperException: /bean/SaleEntry.jsp(16,13) Attribute value request.getParameter('itemID') is quoted with " which must be escaped when used within the value
不明白为什么,请问有人遇到这样的情况吗?今天刚学jsp。表述不清楚的地方请指出。
<jsp:useBean id="entry" class="bean.SaleEntry"/>第一种写法:
<jsp:setProperty
name="entry"
property="itemID"
value='<%= request.getParameter("itemID")%>'/>第二种写法:
<jsp:setProperty
name="entry"
property="itemID"
value="<%= request.getParameter("itemID")%>"/>
第三种写法:
<jsp:setProperty
name="entry"
property="itemID"
value="<%= request.getParameter('itemID')%>"/>在做实验的时候第一种写法没有出现问题。但是在运行第一和第二种写法的时候,有时候能输出正确结果,有时候却有异常(重新刷新页面):org.apache.jasper.JasperException: /bean/SaleEntry.jsp(16,13) Attribute value request.getParameter("itemID") is quoted with " which must be escaped when used within the value或者:org.apache.jasper.JasperException: /bean/SaleEntry.jsp(16,13) Attribute value request.getParameter('itemID') is quoted with " which must be escaped when used within the value
不明白为什么,请问有人遇到这样的情况吗?今天刚学jsp。表述不清楚的地方请指出。
首先有一个类SaleEntry.class在web-inf/bean下。
<jsp:useBean id="entry" class="bean.SaleEntry"/>第一种写法:
<jsp:setProperty
name="entry"
property="itemID"
value='<%= request.getParameter("itemID")%>'/>第二种写法:
<jsp:setProperty
name="entry"
property="itemID"
value="<%= request.getParameter("itemID")%>"/>
第三种写法:
<jsp:setProperty
name="entry"
property="itemID"
value="<%= request.getParameter('itemID')%>"/>在做实验的时候第一种写法没有出现问题。但是在运行第二和第三种写法的时候,有时候能输出正确结果,有时候却有异常(重新刷新页面):org.apache.jasper.JasperException: /bean/SaleEntry.jsp(16,13) Attribute value request.getParameter("itemID") is quoted with " which must be escaped when used within the value或者:org.apache.jasper.JasperException: /bean/SaleEntry.jsp(16,13) Attribute value request.getParameter('itemID') is quoted with " which must be escaped when used within the value
不明白为什么,请问有人遇到这样的情况吗?今天刚学jsp。表述不清楚的地方请指出。
<jsp:setProperty
name="entry"
property="itemID"
value="<%= request.getParameter("itemID")%>" // 有两对的“ ”时候 最好其中一对用''来代替
value="<%= request.getParameter('itemID')%>"
/>
当出现两对“”“”的时候
比如楼主的这题value="<%= request.getParameter("itemID")%>"
// 如果都是用“” 的话 编译器就不知道该如何判断 "<%= request.getParameter(" 和")%>"肯定是错的 抛异常
// 为了确保是正确情况"itemID"改为'itemID' 这样编译器就不会误判了
所以第三种肯定不对,第一种单引号双引号配对, 并且分开了,
肯定没用,第二种 应该也不会有错,
两个都是分开的, 就是先要执行java代码, 里面与外面并无冲突,我这里一直是这样的, 没见过有异常
参考http://tomcat.apache.org/tomcat-6.0-doc/config/systemprops.html
第二种写法,在tomcat下一般没问题,但是在websphere和weblogic下有问题。
第三种写法:绝对有问题,jsp都无法转译成class文件
<jsp:setProperty
name="entry"
property="itemID"
value="<%= request.getParameter(\"itemID\")%>"/>
也没有问题
肯定都碰到过啊,要不然怎么回答的这么奔放呢,当时第二种写法把我害死了。
第二种写法在标签里面有问题,在js里面是没有问题的(当然都是websphere或者weblogic)