Java Code inside JSP: How to put double quotes

2019-08-30 23:45发布

Our legacy code use Java directly inside JSP. I cannot use EL. I got a problem here:

<jbo:DataSource id="dsyn" appid="AM_Quebec" viewobject="YesnoView1" 
                whereclause='<%="yesno.yn_lang="+locale%>'>

For the whereclause, what I really want is like this:

String yesno_wc = "yesno.yn_lang='" + locale + "'";

Anybody knows how to put the yesno_wc in the where clause? Thanks

标签: jsp jsp-tags
2条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-31 00:06

In Java you can escape double quotes with a backslash.

I might first store that value, here is an example JSP storing the value in a scriptlet, then using a tag with a JSP expression as the value.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
where
<% String withQuotes = " 'column'='\"value\"' "; %>
<c:out value="<%= withQuotes %>"/>

which produces

where 'column'='"value"'
查看更多
乱世女痞
3楼-- · 2019-08-31 00:07

In Java you can escape double quotes with a backslash.

I might first store that value, here is an example JSP storing the value in a scriptlet, then using a tag with a JSP expression as the value.

查看更多
登录 后发表回答