| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 572 人关注过本帖
标题:[讨论]ecplise中jsp+mysql问题和大家分享讨论
取消只看楼主 加入收藏
tigershi10
Rank: 1
等 级:新手上路
帖 子:84
专家分:0
注 册:2006-10-12
收藏
 问题点数:0 回复次数:1 
[讨论]ecplise中jsp+mysql问题和大家分享讨论

我用的是ecplise3.2+myecplise5.1.1+Tomcat 5.0+MySQL5.0+jdk1.5
新建项目名为Test,然后在里面新建了mysql.html和mysql.jsp
功能是把mysql.html写的东西传到mysql.jsp中
程序如下:
(2.1)mysql.html

<html>
<head>
<title>mysql.html</title>
</head>
<body>
<form name="form" action="mysql.jsp" method="post">
<p>姓:<input name ="last_name" type="text" id="last_name"></p>
<p>名:<input name="first_name" type="text" id="first_name"></p>
<p>
<input type="submit" value="提交">
<input type="reset" value="取消">
</p>
</form>
</body>
</html>

(2.2)mysql.jsp

<%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'mysql.jsp' starting page</title>
</head>
<body>
<h2>将信息存人mysql 中</h2>
<%
Connection con=null;
Statement stmt=null;
Statement stmt1=null;
ResultSet rs=null;
request.setCharacterEncoding("gb2312");
String employee_id=null;
String last_name=request.getParameter("last_name");
String first_name=request.getParameter("first_name");
String birth="1986/10/10";
String sex="F";
String new_last_name="";
String new_first_name="";
%>
从mysql.html接收的信息如下:<br>
姓:<%=last_name %>  
名:<%=first_name %>
<%
try
{
Class.forName("org.gjt.mm.mysql.Driver");
String url="jdbc:mysql://localhost/sample_db";
String user="root";
String pass="tiger";
con=DriverManager.getConnection(url,user,pass);
stmt=con.createStatement();
String upd="insert into employee(employee_id,last_name,first_name,birth,sex) values ("+employee_id+",'"+last_name+"','"+first_name+"','"+birth+"','"+sex+"')";
stmt.executeUpdate(upd);
stmt1=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String query="select * from employee";
rs=stmt1.executeQuery(query);
rs.last();
new_last_name=rs.getString("last_name");
new_first_name=rs.getString("first_name");
stmt.close();
stmt1.close();
con.close();
}
catch(SQLException sqle)
{
out.println("sqle="+sqle);
}
finally
{
try
{
if(con!=null)
con.close();
}
catch(SQLException sqle)
{
out.println("sqle="+sqle);
}
}
%>
从employee中取出的新增姓名:<br>
新增姓名:<%=new_last_name+new_first_name %><br>
</body>
</html>

创建一个数据库sample_db并在它下面新建了一个表employee,语句如下
create table employee(
employee_id int unsigned not null auto_increment primary key,
last_name varchar(15) not null,
first_name varchar(15) not null,
birth date not null,
sex enum('M','F') default 'M'
);

当我通过右击项目名,然后选择properties->java build path,选择Libraries标签,
单击Add Externar JARs把mysql-connector-java-5.0.6-bin.jar和mysql-connector-java-5.0.6-bin-g.jar

这2个包加进去时,在mysql.html提交时,会出现如下异常
javax.servlet.ServletException: org.gjt.mm.mysql.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.mysql_jsp._jspService(mysql_jsp.java:141)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:148)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:69)
java.lang.ClassLoader.loadClassInternal(Unknown Source)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.mysql_jsp._jspService(mysql_jsp.java:91)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


意思是说没有找到jdbc驱动:ClassNotFoundException
于是我就把刚才加的2个包给移除了
这时我把刚才2个包拷贝到该项目的lib目录下:Test\WebRoot\WEB-INF\lib
重启tomcat,在mysql.html提交时,又出现如下异常
javax.servlet.ServletException: org/aspectj/lang/Signature
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.mysql_jsp._jspService(mysql_jsp.java:141)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.mysql_jsp._jspService(mysql_jsp.java:91)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

我上网搜了一下是什么原因,说是少了这个jar包aspectj-1.5.3.jar
于是下了一个,网址是从http://www.eclipse.org/aspectj/downloads.php
解开aspectj-1.5.3.jar 将其中下面的lib包里面的aspectjrt.jar包放到该项目的lib目录下:Test\WebRoot\WEB-INF\lib
即现在该项目lib目录下有3个jar包:mysql-connector-java-5.0.6-bin.jar,
mysql-connector-java-5.0.6-bin-g.jar,aspectj-1.5.3.jar
重启tomcat然后运行项目,一切正常

希望能给大家带来帮助,同时谁知道以上的原因,就一起讨论下哦

搜索更多相关主题的帖子: mysql jsp ecplise name 
2007-05-29 22:12
tigershi10
Rank: 1
等 级:新手上路
帖 子:84
专家分:0
注 册:2006-10-12
收藏
得分:0 
我这个帖发在j2ee区,都没人教我,我就在这儿也发一下
大家帮帮我哦

专业源于品质
2007-05-29 22:13
快速回复:[讨论]ecplise中jsp+mysql问题和大家分享讨论
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038811 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved