trying to see if the last character is a '>'......any suggestions
I already know how to check for the character
heres what I got
if (userData.getName().charAt(0)!='<' ) {
thank
trying to see if the last character is a '>'......any suggestions
I already know how to check for the character
heres what I got
if (userData.getName().charAt(0)!='<' ) {
thank
Short version: the last character is at index length-1, watch for null/empty strings, and be careful whether you mean "either end has an angle" (use OR) or "both ends are angle-bracketed" (use AND). originally checked the first character, reminded about the last index, and correctly pointed out the boolean-logic issue.
A small, safe Java helper you can put on the server side (bean/controller) and call from the JSP. It trims, checks for a surrounding pair of angle brackets, and strips them if present:
public static String normalizeName(String name) {
if (name == null) return null;
String s = name.trim();
if (s.matches("^<.+>$")) {
return s.substring(1, s.length() - 1);
}
return s;
} Use this to avoid repeating logic in the JSP and to avoid NullPointerExceptions. If the goal is only to test whether the last character is a '>' without removing anything, do a safe-length check first and test the final character via substring (avoid calling character access on empty strings).
JSP notes and troubleshooting: the "illegal start of expression" and "';' expected" errors come from mismatched scriptlet tags or misplaced parentheses when you mix HTML and <% %>. Prefer preprocessing in a servlet/bean and simply output a sanitized property in the view. Also, if names might contain raw '<' or '>', escape them when printing (for example use JSTL <c:out> or EL) to avoid breaking the page or opening XSS holes — a point raised indirectly by about parsing/HTML content.
Jump to Post— masijade 1,351Why not == '>' ?
Edit: And, of course not 0. Try userData.length() - 1.
Jump to Post— Ezzaral 2,714
userData.endsWith(">")perhaps?Edit: yeah, charAt(userData.length()-1) works just as well
Jump to Post— Ezzaral 2,714Check your parenthesis on the if() statement.
Why not == '>' ?
Edit: And, of course not 0. Try userData.length() - 1.
userData.endsWith(">") perhaps?
Edit: yeah, charAt(userData.length()-1) works just as well
alright...let me check that out..I'll be back to let u know
getting illegal start of expression and ';' expected...Im sure it's something small..or I set it up wrong....take a look
<div id="contactInfo">
<%
if (userData.getName().charAt(0)!='<') || (userData.getName().charAt(userData.getName().length()-1)!='>' ) {
%>
<span> <%=userData.getName()%> •</span>
<%}
%> Check your parenthesis on the if() statement.
Check your parenthesis on the if() statement.
ok I opened up the if:
<div id="contactInfo">
<%
if (userData.getName().charAt(0)!='<' || userData.getName().charAt(userData.getName().length()-1)!='>' ) {
%>
<span> <%=userData.getName()%> •</span> if I put "<sample" for the name...nuthing shows up
but if I put"sample>"..it still displays the string
I would think you'd want an && condition there, not an ||.
if (!userData.getName().startsWith("<") && !userData.getName().endsWith(">") )
This looks to me like the beginning of a html/xml parser of some kind. If I'm wrong well, there ya go.
If I'm not then perhaps you should start looking into regular expressions. As they will help you in the long run.
thanx man
appreciate the help Ezzaral...good lookin playa!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.