我按照网上的这篇文章安装,apache+tomcat可以正常运行,但唯独有jsp+mysql访问数据库时有问题,报错如下,请大家看看:
注:在连接之前我在mysql里做了这样的设定:
参考文章如下:http://linux.chinaunix.net/doc/netconf/2005-01-21/871.shtml(红旗Linux4.1下安装Apahce+Tomcat+PHP+mySQL+vsFTPd实录)
GRANT ALL PRIVILEGES ON *.* TO mysql@localhost IDENTIFIED BY '';
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY '123456';
exception
javax.servlet.ServletException: Server configuration denies access to data source
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.mysql_jsp._jspService(org.apache.jsp.mysql_jsp:82)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
附JSP连接程序:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html><title>Linux下测试JSP页面(Apache+Tomcat+MySQL)</title><body>
<%Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/mysql?user=root&password='123456'&useUnicode=true&characterEncoding=GB2312";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from user";
ResultSet rs=stmt.executeQuery(sql); %>
<table><tr><td>您的第一个字段内容为:</td>
<td>您的第二个字段内容为:</td>
</tr>
<%while(rs.next()) {%>
<tr><td>
<%=rs.getString(1)%> </td><td>
<%=rs.getString(2)%> </td></tr>
<%}%>
</table>
<%out.print("Tomcat+JDK+mySQL完整测试,恭喜你,数据库操作成功!");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>