jsp代码不能运行,问题出在哪
<%@pagelanguage="java"contentType="text/html;charset=GBK"pageEncoding="utf-8"%><%@pag...
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="utf-8"%>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<%
try{
ArrayList al=new ArrayList();
String i;
Connection conn=null;
String url="jdbc:mysql://localhost:3306/wz";
String user="root";
String password="123456";
String driver="com.mysql.jdbc.Driver";
Class.forName(driver);//加载数据库的驱动
conn=DriverManager.getConnection(url, user, password);
if(conn!=null)
{
System.out.println("成功连接Mysql@@@@");
}
Statement ment=conn.createStatement();
ResultSet rs=ment.executeQuery("select name from book");
while(rs.next())
{
String s2=rs.getString(1);
al.add(s2);
}
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
%>
<select>
<%
for(int x=0;x<al.size();x++ )
{
%>
<option value="<%=al.get(x)%>"><%=al.get(x)%></option>
<%
}
%>
</select>
</body>
</html> 展开
pageEncoding="utf-8"%>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<%
try{
ArrayList al=new ArrayList();
String i;
Connection conn=null;
String url="jdbc:mysql://localhost:3306/wz";
String user="root";
String password="123456";
String driver="com.mysql.jdbc.Driver";
Class.forName(driver);//加载数据库的驱动
conn=DriverManager.getConnection(url, user, password);
if(conn!=null)
{
System.out.println("成功连接Mysql@@@@");
}
Statement ment=conn.createStatement();
ResultSet rs=ment.executeQuery("select name from book");
while(rs.next())
{
String s2=rs.getString(1);
al.add(s2);
}
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
%>
<select>
<%
for(int x=0;x<al.size();x++ )
{
%>
<option value="<%=al.get(x)%>"><%=al.get(x)%></option>
<%
}
%>
</select>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询