当前位置: 代码迷 >> Java Web开发 >> [讨论]ecplise中jsp+mysql问题和大家分享讨论
  详细解决方案

[讨论]ecplise中jsp+mysql问题和大家分享讨论

热度:302   发布时间:2007-05-29 17:22:49.0
[讨论]ecplise中jsp+mysql问题和大家分享讨论

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

<html>
<head>
<title>mysql</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接收的信息如下:<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提交时,会出现如下异常
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提交时,又出现如下异常
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然后运行项目,一切正常

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

[此贴子已经被作者于2007-5-29 21:17:23编辑过]

搜索更多相关主题的帖子: mysql  jsp  ecplise  name  

----------------解决方案--------------------------------------------------------

大家多多指教


----------------解决方案--------------------------------------------------------
没有用过这个包!
----------------解决方案--------------------------------------------------------

有人知道不?
.....


----------------解决方案--------------------------------------------------------
  相关解决方案