我用myeclipse做的JSP页面,老是报错,请大神帮看一下,谢谢
平台:jdk1.8.0-25,myeclipse10,tomcat6.0,jdbc5.1.34,mysql5.5在环境变量里只配置了jdk,server运行时没报错,但在...
平台:jdk1.8.0-25,myeclipse10,tomcat6.0,jdbc5.1.34,mysql5.5
在环境变量里只配置了jdk,server运行时没报错,但在浏览器里输入localhost:8080/DbConnection/testConnection.jsp和localhost:8080/testConnection.jsp都报404
下面是页面代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType = "text/html; charset = UTF-8" %>
<%@ page import = "com.mysql.jdbc.Driver" %>
<%@ page import = "java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'testConnection.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. <br>
<%
String driverName = "com.mysql.jdbc.Driver";
String userName = "root";
String userPasswd = "root";
String dbName = "test";
String tableName = "student";
String url = "jdbc:mysql://192.168.0.99:8080/test?user = userName&password = userpasswd";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql = "select * from student";
ResultSet rs = statement.executeQuery(sql);
ResultSetMetaData rmeta = rs.getMetaData();
int numColumns = rmeta.getColumnCount();
out.print("sno");
out.print("|");
out.print("sname");
out.print("<br>");
while(rs.next()){
out.print(rs.getString("sno") + " ");
out.print("|");
out.print(rs.getString("sname"));
out.print("<br>");
}
out.print("<br>");
out.print("数据库操作成功,恭喜你");
rs.close();
statement.close();
connection.close();
%>
</body>
</html> 展开
在环境变量里只配置了jdk,server运行时没报错,但在浏览器里输入localhost:8080/DbConnection/testConnection.jsp和localhost:8080/testConnection.jsp都报404
下面是页面代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType = "text/html; charset = UTF-8" %>
<%@ page import = "com.mysql.jdbc.Driver" %>
<%@ page import = "java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'testConnection.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. <br>
<%
String driverName = "com.mysql.jdbc.Driver";
String userName = "root";
String userPasswd = "root";
String dbName = "test";
String tableName = "student";
String url = "jdbc:mysql://192.168.0.99:8080/test?user = userName&password = userpasswd";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql = "select * from student";
ResultSet rs = statement.executeQuery(sql);
ResultSetMetaData rmeta = rs.getMetaData();
int numColumns = rmeta.getColumnCount();
out.print("sno");
out.print("|");
out.print("sname");
out.print("<br>");
while(rs.next()){
out.print(rs.getString("sno") + " ");
out.print("|");
out.print(rs.getString("sname"));
out.print("<br>");
}
out.print("<br>");
out.print("数据库操作成功,恭喜你");
rs.close();
statement.close();
connection.close();
%>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询