Question regarding quotation marks when mixing jsp and html forms

Hey all

I'm trying to escape some quotation marks but can't figure out how to do it.

<form METHOD"POST" ACTION="mockup.jsp">

<select size="1" name="view">

<% out.println(" <option value="yes">" +getTopic);" %></option> //Problem

</select>

<input type="submit" value="Submit">

</form>

Tomcat output:

An error occurred at line: 117 in the jsp file: /mockup/mockup.jsp

Generated servlet error:

Syntax error, insert ")" to complete MethodInvocation

An error occurred at line: 117 in the jsp file: /mockup/mockup.jsp

Generated servlet error:

Syntax error, insert ";" to complete Statement

[950 byte] By [syncroa] at [2007-10-2 5:16:21]
# 1

There are several ways to do this:

You use a back-slash to escape quotes in a String.

<% out.println(" <option value=\"yes\">" +getTopic); %>

or use a single quote instead of double quote for HTML attributes

<% out.println(" <option value='yes'>" +getTopic); %>

or use an expression rather than scriptlet code

<option value="yes"><%= getTopic %></option>

It looks to me like you have an extra " in ther after the semi colon as well.

Hope this helps,

evnafets

evnafetsa at 2007-7-16 1:18:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...