国光磷酸二氢钾叶面肥:jsp看看那里错误啊。帮我看看

来源:百度文库 编辑:中科新闻网 时间:2024/05/05 06:01:21
<jsp:useBean id="DBConnection" scope="page" class="com.guestbook.DBConnection"/>
<%!
public void conn(){
try{
public Connection conn=DBConnection.getConnectionToAccess(application.getRealPath("data/guestbook.mdb"));
public Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}catch(Exception e){
//e.printStackTrace();
out.print("数据库连接失败");
}
}
%>

<%
conn();
%>

错误提示
description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 4 in the jsp file: /main.jsp
Generated servlet error:
Illegal modifier for the variable conn; only final is permitted

在<%!%>
中定义的方法如果要用的话需要有实例对象来调用的!在<%!%>应该定义一个类,在<%%>中就可以调用这个类定义的方法了

在JSP里面是不能写方法的,Servlet在编译的时候就会把JSP里的内容放到Service方法里,方法里是不能套方法的,如果需要的话可以自己建个类,在JSP里面调用