日期:2014-05-16  浏览次数:20923 次

jsp中<a>标签的输出问题。
在JSP中,遇到这样一个问题,搞不清楚out.prijt()语句为啥不能输出,代码如下,麻烦高手看看。
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.sql.*" %>

<HTML><BODY bgcolor=cyan>
<% Connection con;
ResultSet rs;
Statement slmt;
int i=1,b;
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=shopping","sa","200870");
slmt=con.createStatement();
String a1="select name,basePrice from product";
slmt.executeQuery(a1);
rs = slmt.executeQuery(a1);
out.print("<table border=2>");
out.print("<tr>");
out.print("<th width=50>"+"name");
out.print("<th width=50>"+"basePrice");

out.print("</tr>");
while (rs.next()) {
b=i++;
  out.print("<tr>");
  out.print("<td>"+b+"</td> ");
  out.print("<td >");
  错误是这里 out.print("<a href="test.jsp">+rs.getString("name")");
  out.print("</a>");
  out.print("</td>");
  out.print("<td>"+rs.getString("name")+"</td> ");
  out.print("<td>"+rs.getString("basePrice")+"</td>" );
  out.print("</tr>");
}
out.print("</table>");
//rs.close();
//slmt.close();// 关闭命令对象连接
con.close();// 关闭数据库连接
}
catch(ClassNotFoundException e){
out.print(e);
// e.printStackTrace();
//System.exit(0);
}
catch(SQLException e){
out.print(e);
//e.printStackTrace();
//System.exit(0);
}
%>
</BODY></HTML>
请求后的错误:An error occurred at line: 27 in the jsp file: /SQL.jsp
Syntax error, insert ")" to complete MethodInvocation

An error occurred at line: 27 in the jsp file: /SQL.jsp

An error occurred at line: 27 in the jsp file: /SQL.jsp
Syntax error on tokens, delete these tokens
Syntax error, insert ";" to complete Statement

------解决方案--------------------
错误是这里 out.print("<a href="test.jsp">+rs.getString("name")");

改成单引号out.print("<a href='test.jsp'>"+rs.getString("name"));