请问jsp大虾:在*.jsp文件中可以有自己独立编写的类吗?

littledapan 2001-08-22 08:53:12
我的程序如下:
register.jsp

<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=gb2312"%>

<html>
<head>
<title>register</title>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
</head>
<body bgcolor="#FFFFFF">




<%


class db{
Connection con;
Statement st;
ResultSet rs;

db(){
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();

//加载 mm.mysql.driver
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ecogrid","dapan","780318");
//创建数据库联接
}
catch (Exception R)
{
System.err.println("Unable to load driver.");
R.printStackTrace();

}

}


db mysql=new db();
try{
mysql.st=mysql.con.createStatement();
String strsql = "insert into jobapply(account,passwd,name,company,ecogrid_card,ecogrid_passwd,email) VALUES(" + request.getParameter("account") + "," + request.getParameter("passwd") + "," + request.getParameter("name") + "," + request.getParameter("ecogrid_card") + "," + request.getParameter("ecogrid_passwd") + "," + request.getParameter("email") +");";
mysql.st.executeQuery(strsql);


//st.executeQuery("insert into jobapply(account,passwd,name,company,ecogrid_card,ecogrid_passwd,email) VALUES(request.getParameter("account"),request.getParameter("passwd"),request.getParameter("name"),request.getParameter("ecogrid_card"),request.getParameter("ecogrid_passwd"),request.getParameter("email");");
//System.out.println(mysql.rs.getString(1));

} catch (SQLException E)
{
System.out.println("hi");
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}

%>



</body>
</html>
结果出现下列问题
Internal Servlet Error:

org.apache.jasper.JasperException: Unable to compile class for JSPC:\jakarta-tomcat-3.2.3\work\localhost_8080%2Fexamples\_0002fregister_0002ejspregister_jsp_0.java:90: Type expected.
try{
^
1 error
请问这是什么原因呢?期待着您的解答!

...全文
106 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yanghui88 2001-08-22
也可以不一定要是bean,做成类,放在classpath其中的一个目录下,然后在.jsp文件开头就象平时import一样import进来就可以了
<%@ page import="java.sql.*,java.io.*,javax.naming.*,javax.sql.*,java.util.*" %>
回复
rinehart 2001-08-22
还是把要用的类做成bean吧!
回复
hexiaofeng 2001-08-22
class db
{
Connection con;
Statement st;
ResultSet rs;

db()
{
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();

//加载 mm.mysql.driver
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ecogrid","dapan","780318");
//创建数据库联接
}
catch (Exception R)
{
System.err.println("Unable to load driver.");
R.printStackTrace();

}

}
}

少了一个"}"
回复
skyyoung 2001-08-22
类不行,方法可以,但两者都不提倡。
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2001-08-22 08:53
社区公告
暂无公告