我现在在这个 JSP 上工作得很快,感觉我在这个 JSP 业务上学得很快。
但我不禁认为这是不对的?我已经在我的 locathost 下尝试过它,但当它通过我的浏览器吐出时我遇到了问题。所以我觉得我的结构错了,但老实说,; 无法锻炼出我出错的地方,我已经做了大约 5 个小时的 JSP,所以请给我这个怀疑的好处。
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<%@ page import="java.io.*" import="java.sql.*"%>
</head>
<body>
<!-- BELOW IS DATABASE CONNECTION SET UP -->
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:database11");
// END OF DATABASE CONNECTION SET UP
// START OF TESTING
String mysql="select * from hotels";
Statement s=con.createStatement();
ResultSet rst=s.executeQuery(mysql);
out.println("<table border='1' width='70%'>");
out.println("<tr>");
out.println("<td width='10%'>" + rst.getString ("NameofPlace") + "</td>");
out.println("<td width='10%'>" + rst.getString ("NameofPlace") + "</td>");
out.println("<td width='10%'>" + rst.getString ("Country") + "</td>");
out.println("<td width='10%'>" + rst.getString ("PricePerNight") + "</td>");
out.println("<td width='10%'>" + rst.getString ("MaximumPersons") + "</td>");
out.println("<td width='10%'>" + rst.getString ("StarRating") + "</td>");
out.println("<td width='20%'>" + rst.getString ("Description") + "</td>");
out.println("</tr>");
while (rst.next()) {
// Column Details of hotels
out.println("<tr>");
out.println("<td width='10%'>" + rst.getString ("NameofPlace") + "</td>");
out.println("<td width='10%'>" + rst.getString ("NameofPlace") + "</td>");
out.println("<td width='10%'>" + rst.getString ("Country") + "</td>");
out.println("<td width='10%'>" + rst.getString ("PricePerNight") + "</td>");
out.println("<td width='10%'>" + rst.getString ("MaximumPersons") + "</td>");
out.println("<td width='10%'>" + rst.getString ("StarRating") + "</td>");
out.println("<td width='20%'>" + rst.getString ("Description") + "</td>");
out.println("</tr>");
}
out.println("</table>");
rst.close();
con.close();
%>
</body>
</html>
如果有什么我做错了,请告诉我,因为我可以想象它会非常整洁,结构良好或完美。
如果您对我在做什么感到好奇,请参阅我今天早上早些时候的帖子: https ://stackoverflow.com/questions/10485667/university-jsp-booking-project#comment13551068_10485667
但是为什么它不起作用,非常感谢任何帮助!?
我的错误:
org.apache.jasper.JasperException: Exception in JSP: /0906055/index.jsp:24
21:
22: out.println("<table border='1' width='70%'>");
23: out.println("<tr>");
24: out.println("<td width='10%'>" + rst.getString ("NameofPlace") + "</td>");
25: out.println("<td width='10%'>" + rst.getString ("NameofPlace") + "</td>");
26: out.println("<td width='10%'>" + rst.getString ("Country") + "</td>");
27: out.println("<td width='10%'>" + rst.getString ("PricePerNight") + "</td>");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:395)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
javax.servlet.ServletException: [Microsoft][ODBC Driver Manager] Invalid cursor state
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp._0906055.index_jsp._jspService(index_jsp.java:108)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(Unknown Source)
sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(Unknown Source)
sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
org.apache.jsp._0906055.index_jsp._jspService(index_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.35 logs.