ChadCourtney
03-06-2007, 03:14 PM
I have created a JSP file that retrieves the contents of a dtabase table. I am having issues with the ampersand character (&) in my data set. Is there a way that as I am generating the results of the jsp into an XML feed that I can urlencode the result?
My jsp file is as follows:
-----------------------------------------------------------------------------------------------------------------------
<%@ page import="java.sql.*"%>
<%@ page contentType = "text/html; charset=UTF-8" %>
<resultset>
<%
Connection connection = null;
try {
Class.forName("org.gjt.mm.mysql.Driver"); // 1
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/asset","root",""); // 2
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select id, description from assets limit 10");
while (rs.next()) {
%>
<asset id="<%= rs.getInt("id")%>" description="<%= (rs.getString("description")%>" />
<%
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
connection.close();
} catch (SQLException e) {
}
}
%>
</resultset>
JSP result is as follows:
----------------------------------------------------------------------------------------------------------
<resultset>
<asset id="1154079" description="COE PANEL METER SUPPLY" />
<asset id="1154080" description="TURBINE MONITORING PANEL" />
<asset id="1154081" description="TURBINE SELSYN INDICATORS" />
<asset id="1154082" description="TURBINE SELSYN INDICATORS POWER SUPPLY" />
<asset id="1154083" description="SLIDE GATE PANEL" />
<asset id="1154084" description="SLIDE GATE SELSYN INDICATORS" />
<asset id="1154085" description="SELSYN INDICATOR POWER SUPPLY" />
<asset id="1154086" description="SLIDE GATE 5V CONVERTERS" />
<asset id="1154087" description="PLC RACK 7" />
<asset id="1154089" description="MAIN POWER TRANSFORMERS & 138KV EQUIPMENT" />
</resultset>
------------------------------------------------------------------------------------------
It is the tenth record that contains the & character that is causing the problem.
Thx Chad Courtney
My jsp file is as follows:
-----------------------------------------------------------------------------------------------------------------------
<%@ page import="java.sql.*"%>
<%@ page contentType = "text/html; charset=UTF-8" %>
<resultset>
<%
Connection connection = null;
try {
Class.forName("org.gjt.mm.mysql.Driver"); // 1
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/asset","root",""); // 2
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select id, description from assets limit 10");
while (rs.next()) {
%>
<asset id="<%= rs.getInt("id")%>" description="<%= (rs.getString("description")%>" />
<%
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
connection.close();
} catch (SQLException e) {
}
}
%>
</resultset>
JSP result is as follows:
----------------------------------------------------------------------------------------------------------
<resultset>
<asset id="1154079" description="COE PANEL METER SUPPLY" />
<asset id="1154080" description="TURBINE MONITORING PANEL" />
<asset id="1154081" description="TURBINE SELSYN INDICATORS" />
<asset id="1154082" description="TURBINE SELSYN INDICATORS POWER SUPPLY" />
<asset id="1154083" description="SLIDE GATE PANEL" />
<asset id="1154084" description="SLIDE GATE SELSYN INDICATORS" />
<asset id="1154085" description="SELSYN INDICATOR POWER SUPPLY" />
<asset id="1154086" description="SLIDE GATE 5V CONVERTERS" />
<asset id="1154087" description="PLC RACK 7" />
<asset id="1154089" description="MAIN POWER TRANSFORMERS & 138KV EQUIPMENT" />
</resultset>
------------------------------------------------------------------------------------------
It is the tenth record that contains the & character that is causing the problem.
Thx Chad Courtney