Hello Expert I was wondering if you could help me I need to be able to display quotes and double quotes in my textbox on my jsp page, I ran into problems so i found out i can use HTMLEncode but i need to be able to pass a value to my java and display it back on my jsp page. I was wondering if you can help me here is what i have so far.
//Source from
http://ocw.mit.edu/NR/rdonlyres/Health-Sciences-and-Technology/HST-950JMedical-//ComputingSpring2003/D7B87450-BD26-4DA5-9696-DCBD2BEFFA81/0/entity_java.txthtmlencodes.java
package edu.conestoga.admin.news;
import java.text.*;
import java.util.*;
public class htmlencodes {
private static final char c[] = { '<', '>', '&', '\"'};
private static final String expansion[] = {"<", ">", "&",
"""};
public static String HTMLEncode(String s) {
StringBuffer st = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
boolean copy = true;
char ch = s.charAt(i);
for (int j = 0; j < c.length ; j++) {
if (c[j]==ch) {
st.append(expansion[j]);
copy = false;
break;
}
}
if (copy) st.append(ch);
}
return st.toString();
}
}
then my jsp page is as follows:
<%@ include file="../include/constants
.jsp" %>
<%@ page language="java" %>
<%@ page import="edu.conestoga.admi
n.news.htm
lencodes" %>
<%
int NewsID = Integer.parseInt((String) request.getParameter("News
ID"));
String Title = (String) request.getParameter("Titl
e").trim()
;
String users = htmlencodes.HTMLEncode(tes
ting);
%>
<table border="0" bordercolor="#111111" width="600" height="770">
<tr>
<td width="37%" height="22"><b><font face="Trebuchet MS" size="2">News Title</font></b></td>
<td><% out.println(HTMLEncode('<%
=Title%>' ))%></td>
</tr>
</table>
but this code does not work can you help me please.
Start Free Trial