jsp跳转到下个页面的问题(程序如下)
下面的程序是我从书上抄写的,其他都没有什么错误,就是在编译时出现try without catch or finally ;}expect;这两个错误;
书上说JSP不会抛出
SQLException,可以通过编译,可是在我这里为什么不行呢?
辛苦大家了!!!
<%@page contentType= "text/html; charset=GBK "
errorPage= "error.jsp " %>
<%@page import= "bookstore.* "%>
<%@page import= "java.sql.* "%>
<jsp:useBean id= "userBean " scope= "page " class= "bookstore.User "/>
<jsp:setProperty name= "userBean " property= "* "/>
<%
Connection conn = null;
try {
conn = DBConnection.getConnection();
PreparedStatement pstat = conn.prepareStatement(
"select name from user where id=? and password=? ");
//pstat.setint(1,userBean.getId());
pstat.setInt(1, userBean.getId());
pstat.setString(2, userBean.getPassword());
ResultSet rs = pstat.executeQuery();
if (rs.next()) {
userBean.setId(rs.getInt(1));
session.setAttribute( "ses_userBean ", userBean);
%>
<jsp:forward page= "welcome.jsp "> </jsp:forward>
<%
} else {%>
<jsp:forward page= " "> </jsp:forward>
}
}
finally{
if(conn!=null)
conn.close();}
%>
------解决方案-------------------- <jsp:forward page= " "> </jsp:forward>
<% //---这个地方少了个
}
}
finally{
if(conn!=null)
conn.close();}
%>
------解决方案--------------------bigc2001(大C) ( ) 信誉:97
<jsp:forward page= " "> </jsp:forward>
<% //---这个地方少了个
}
}
finally{
if(conn!=null)
conn.close();}
%>
------解决方案-------------------- <%@page contentType= "text/html; charset=GBK " errorPage= "error.jsp " %>
<%@page import= "bookstore.* "%>
<%@page import= "java.sql.* "%>
<jsp:useBean id= "userBean " scope= "page " class= "bookstore.User "/>
<jsp:setProperty name= "userBean " property= "* "/>
<%
Connection conn = null;
try {
conn = DBConnection.getConnection();
PreparedStatement pstat = conn.prepareStatement( "select name from user where id=? and password=? ");
pstat.setInt(1, userBean.getId());
pstat.setString(2, userBean.getPassword());
ResultSet rs = pstat.executeQuery();
if (rs.next()) {
userBean.setId(rs.getInt(1));
session.setAttri