<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="ISO-8859-1" import="java.sql.*"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Inline Editing: Form Controls</title>
<script type="text/javascript" src="../../lib.js"></script>
<script type="text/javascript" src="inline-editing.js"></script>
<link type="text/css" rel="stylesheet" href="Presidents.css">
</head>
<body>
<%
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:Presidents");
String sql = "SELECT PresidentID, FirstName, LastName, Bio FROM Presidents";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
out.write("<h1>Presidents</h1>");
out.write("<p>Double click on any cell to edit the field. Click off the field to save your change.</p>");
out.write("<table>");
while (rs.next())
{
out.write("<tr id='" + rs.getString("PresidentID") + "'>");
/*line 31*/ out.write("<td class="editable" title='FirstName'>" + rs.getString("FirstName") + "</td>");
/*line 32*/ out.write("<td class="editable" title='LastName'>" + rs.getString("LastName") + "</td>");
/*line 33*/ out.write("<td class="editable" title='Bio'>" + rs.getString("Bio") + "</td>");
out.write("</tr>");
}
out.write("</table>");
}
catch(Exception e)
{
out.write("failed: " + e.toString());
}
finally
{
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
}
%>
</body>
</html>
我收到以下錯誤的線31,32,33數據庫連接使用JSP
The method write(String, int, int) in the type Writer is not applicable for the arguments (String, String)
Syntax error on token "editable", , expected
我應該怎麼做才能解決這個問題?
首先不要在jsp中編寫數據庫連接邏輯。 – 2011-06-10 09:19:18
Harry Joy是對的,你應該使用servlets或其他後端邏輯來處理數據庫查詢。 JSP通常只是顯示來自後端數據的啞模塊。當你有時間的時候看看一些MVC教程。 – deltaforce2 2011-06-10 09:22:23