【发布时间】:2011-01-23 21:48:04
【问题描述】:
我正在开发一个 servlet,它与数据库建立连接,获取其中一个表的信息,然后将此信息发送到 jsp 文件。该文件将在浏览器上打印信息表,并添加单选按钮,让我们可以选择其中一行。
servlet 如下所示:
List<InfoBean> items = new ArrayList<InfoBean>();
if (!conexion.isClosed()){
Statement st = (Statement) conexion.createStatement();
ResultSet rs = st.executeQuery("select * from lista_audio" );
while (rs.next())
{items.add(getRow(rs));}
conexion.close();}
req.getSession().setAttribute("items", items);
在 JSP 文件中,我可以打印包含信息的表格,添加单选按钮,用户将使用这些单选按钮选择 1 行并使用我可以添加的表单将所选信息发送到 servlet:
< form action="administ" method=get enctype=multipart/form-data>
< table>
< table border=\"1\">< tr>< th>Title< /th>< th>Author< /th>< th>Album< /th>< /tr>
< c:forEach items="${items}" var="item">
< tr>< td><input type="radio" name="SongInfo" value=${item.title}>
< td>${item.title}< /td>
< td>${item.author}< /td>
< td>${item.album}< /td>< /tr>
< /c:forEach>
< /table>
在“值”字段中,我应该能够将存储在 ${item.title} 中的信息发送到 servlet。当我设置 value = ${item.title} 并且标题是,例如“保镖”时,在 servlet 中我可以检索的信息只是“The”。看起来它发送位于字符串第一个空格之前的字符。我怎样才能得到整个字符串?
谢谢
【问题讨论】:
标签: java html forms jsp servlets