Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Escaping double quotes (") in jsp and other bad smells.

843840Jan 23 2008 — edited Jan 23 2008
Greetings,

I am trying to work out the best way to remove double quotes at the presentation / JSP layer, when returning requests as JSON via AJAX, my framework is Struts 1.1.

I have thought of the following:
- Use a static function in the jsp page, escaping quotes. Not got this working yet but... Euuu.
- When returning the List object from the Logic layer (in the Action layer), loop through the items returned, escaping the various properties of the entity. Yuck.
- Create special methods in the entity, such as 'getDescriptionEscaped' that will do this for me. OMG!

Architecturally, what's the best way to do this?

Have some code:
page.jsp
<%@ page contentType="text/html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page import="Net2U.Nucleo.Utilidades.Autocompletar" %>
{"ucdtPadre":
	[
<logic:notEmpty name="lstEntidades" scope="request">
	<c:forEach var="Entidad" items="${lstEntidades}" varStatus="status">
		{
			"codigo": "<c:out value="${Entidad.codigoUCDT}"/>" ,
			"descripcion": "<c:out value="${Entidad.descripcionUCDT}" escapeXml="false"/>" 
			<% //=Autocompletar.magicQuotes(<c:out value="${Entidad.descripcionUCDT}"/>) %>
		} <c:if test="${!status.last}">,</c:if>
	</c:forEach>
</logic:notEmpty>
	]
}
Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 20 2008
Added on Jan 23 2008
3 comments
1,347 views