这段程序哪错了? JSP+TOMCAT+MYSQL环境ECLIPSE
<%@pagecontentType="text/html;charset=gb2312"%><%@pageimport="java.sql.*"%><html><hea...
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>查询</title>
</head>
<body>
<%
while(session.getAttribute("roleno"))
{
if(request.getParameter("name")==null)
{
%>
<form action="" method="post" id="form1" name="form1">
<p align="center"><span class="STYLE4">输入你要查询的资料</span>
<label>
<input type="text" name="name" id="name">
</label>
</p>
<p align="center">
<label>
<input type="submit" name="seek" value="模糊查询">
</label>
</p>
</form>
<p><%
}
else{
String name=(String)request.getParameter("name").trim();
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/zlgl?user=root&password=123456&useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "SELECT * FROM paper WHERE Name='%"+name+"'%";
ResultSet rs=stmt.executeQuery(sql);
String ntemp="a";
while(rs.next()){
ntemp=(String)rs.getString("Name").trim();
}
if(ntemp=="a"){out.print("没有相关资料");%><a href="login.jsp">返回</a></p><%}
else{
for(int i=0;i<db.getCount("paper");i++){
%>
<tr>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.Name",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.zz",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.slqk",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.Time",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.bz",i)%></div></td>
</tr>
<p><%}
}
%></p>
</body>
</html>
总是提示 TRY WITHOUT CATCH
CATCH WITHOUT TRY
可是我也没写TRY CATCH啊?
高人给指点一下
第一个答复我试了.还是那个错误.而且缺少TRY是第一行,就是<%@page……%>那行.
缺少CATCH是最后一行</html>下面一行 展开
<%@ page import="java.sql.*"%>
<html>
<head>
<title>查询</title>
</head>
<body>
<%
while(session.getAttribute("roleno"))
{
if(request.getParameter("name")==null)
{
%>
<form action="" method="post" id="form1" name="form1">
<p align="center"><span class="STYLE4">输入你要查询的资料</span>
<label>
<input type="text" name="name" id="name">
</label>
</p>
<p align="center">
<label>
<input type="submit" name="seek" value="模糊查询">
</label>
</p>
</form>
<p><%
}
else{
String name=(String)request.getParameter("name").trim();
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/zlgl?user=root&password=123456&useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "SELECT * FROM paper WHERE Name='%"+name+"'%";
ResultSet rs=stmt.executeQuery(sql);
String ntemp="a";
while(rs.next()){
ntemp=(String)rs.getString("Name").trim();
}
if(ntemp=="a"){out.print("没有相关资料");%><a href="login.jsp">返回</a></p><%}
else{
for(int i=0;i<db.getCount("paper");i++){
%>
<tr>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.Name",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.zz",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.slqk",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.Time",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.bz",i)%></div></td>
</tr>
<p><%}
}
%></p>
</body>
</html>
总是提示 TRY WITHOUT CATCH
CATCH WITHOUT TRY
可是我也没写TRY CATCH啊?
高人给指点一下
第一个答复我试了.还是那个错误.而且缺少TRY是第一行,就是<%@page……%>那行.
缺少CATCH是最后一行</html>下面一行 展开
2个回答
展开全部
意思叫你写
try{
}
catch{
}
捕捉异常啊。
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>查询</title>
</head>
<body>
<%
while(session.getAttribute("roleno"))
{
if(request.getParameter("name")==null)
{
%>
<form action="" method="post" id="form1" name="form1">
<p align="center"><span class="STYLE4">输入你要查询的资料</span>
<label>
<input type="text" name="name" id="name">
</label>
</p>
<p align="center">
<label>
<input type="submit" name="seek" value="模糊查询">
</label>
</p>
</form>
<p><%
}
else{
String name=(String)request.getParameter("name").trim();
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch(ClassNotFoundException e)
{
out.print("找不到类!");
}
String url ="jdbc:mysql://localhost/zlgl?user=root&password=123456&useUnicode=true&characterEncoding=8859_1";
try{
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "SELECT * FROM paper WHERE Name='%"+name+"'%";
ResultSet rs=stmt.executeQuery(sql);
String ntemp="a";
while(rs.next()){
ntemp=(String)rs.getString("Name").trim();
}
if(ntemp=="a"){out.print("没有相关资料");%><a href="login.jsp">返回</a></p><%}
else{
for(int i=0;i<db.getCount("paper");i++){
%>
<tr>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.Name",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.zz",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.slqk",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.Time",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.bz",i)%></div></td>
</tr>
<p><%
}
}
conn.close();
}
catch(Exception ex)
{
out.print(ex.getMessage());
}
%></p>
</body>
</html>
try{
}
catch{
}
捕捉异常啊。
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>查询</title>
</head>
<body>
<%
while(session.getAttribute("roleno"))
{
if(request.getParameter("name")==null)
{
%>
<form action="" method="post" id="form1" name="form1">
<p align="center"><span class="STYLE4">输入你要查询的资料</span>
<label>
<input type="text" name="name" id="name">
</label>
</p>
<p align="center">
<label>
<input type="submit" name="seek" value="模糊查询">
</label>
</p>
</form>
<p><%
}
else{
String name=(String)request.getParameter("name").trim();
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch(ClassNotFoundException e)
{
out.print("找不到类!");
}
String url ="jdbc:mysql://localhost/zlgl?user=root&password=123456&useUnicode=true&characterEncoding=8859_1";
try{
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "SELECT * FROM paper WHERE Name='%"+name+"'%";
ResultSet rs=stmt.executeQuery(sql);
String ntemp="a";
while(rs.next()){
ntemp=(String)rs.getString("Name").trim();
}
if(ntemp=="a"){out.print("没有相关资料");%><a href="login.jsp">返回</a></p><%}
else{
for(int i=0;i<db.getCount("paper");i++){
%>
<tr>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.Name",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.zz",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.slqk",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.Time",i)%></div></td>
<td height="20"><div align="center"><%=db.getAttributeStr("paper.bz",i)%></div></td>
</tr>
<p><%
}
}
conn.close();
}
catch(Exception ex)
{
out.print(ex.getMessage());
}
%></p>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询