我用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>
展开
 我来答
jpsbbt
2015-03-05 · TA获得超过1548个赞
知道小有建树答主
回答量:1060
采纳率:100%
帮助的人:537万
展开全部
404错误是没有找到指定页面,你的url中缺少应用的名称,应用的名称一般同工程的名称;
比如,你的工程名称是app,则你的url应该为:localhost:8080/app/testConnection.jsp
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式