我才开始学习想做个简单的增加删除修改查功能的小例子,可是做了很久,也没什么起色,希望大侠可以帮忙。
小女感激不尽。
我把我写的发上来,希望大家可以指点我哪里错了。
配置文件:
<!-- 数据源连接 -->
  <data-sources>
  <data-source type="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
    <set-property
      property="driverClassName"
      value="oracle.jdbc.driver.OracleDriver" />
    <set-property
      property="url"
      value="jdbc:oracle:thin:@localhost:1521:orcl" />
    <set-property
      property="username"
      value="scott"/>
    <set-property
      property="password"
      value="tiger" />
    <set-property
      property="maxActive"
      value="10" />
    <set-property
      property="maxWait"
      value="5000" />
    <set-property
      property="defaultAutoCommit"
      value="true" />
</data-source>
  </data-sources>
  
  <form-beans>
   <form-bean name="test3_1zhuce_form" type="com.Test3.formbean.test3_1zhuce_form"></form-bean>
  </form-beans>
  
  <global-exceptions />
  <global-forwards />
  <action-mappings>
   <action   path="/test3_1zhuce"
              type="com.Test3.Action.test3_1zhuce_action"
              name="test3_1zhuce_form"
              scope="request"
              input="/1zhuce.jsp"
              validate="true">
              <forward name="ok" path="/2denglu.html"/>
</action>
  </action-mappings>
  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>
数据库表:
create table test3_user(
       id number ,
     user_name  varchar(20),
     user_password varchar(20)
    );
页面:1zhuce.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>注册界面</title>
</head>
<body>
<form name="form1" method="post" action="test3_1zhuce">
  <table width="200" border="1" align="center">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&#29992;&#25143;&#21517;&#65306;</td>
      <td><input type="text" name="user_name"></td>
    </tr>
    <tr>
      <td>&#23494;&#30721;&#65306;</td>
 
      <td><input type="password" name="user_password">
      </td>
    </tr>
    <tr>
      <td>&#30830;&#35748;&#23494;&#30721;&#65306;</td>
      <td><input type="password" name="user_repassword"></td>
    </tr>
    <tr>
      <td><input type="submit" name="zhuce" value="zhuce"></td>
      <td><input type="reset" name="quxiao" value="quxiao"></td>
    </tr>
  </table>
</form>
</body>
</html>
form:
package com.Test3.formbean;import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;public class test3_1zhuce_form extends ActionForm{
String user_name;
String user_password;



public test3_1zhuce_form() {
super();
}
public test3_1zhuce_form(String user_name, String user_password) {
super();
this.user_name = user_name;
this.user_password = user_password;
}
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
public String getUser_password() {
return user_password;
}
public void setUser_password(String user_password) {
this.user_password = user_password;
}

public void reset(ActionMapping mapping, HttpServletRequest request) {

 user_name = null;
 user_password = null;
}
}dao:package com.Test3.dao;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;import javax.sql.DataSource;import com.Test3.formbean.test3_1zhuce_form;public class test3_dao {

private DataSource ds; public test3_dao() {
super();
} public test3_dao(DataSource ds) {
super();
this.ds = ds;
}


//用户注册
public void user_insert(test3_1zhuce_form user) throws SQLException{
Connection conn = ds.getConnection();
PreparedStatement ps = conn.prepareStatement("insert into test3_user values(?,?)");
ps.setString(1, user.getUser_name());
ps.setString(2, user.getUser_password());
ps.executeUpdate();
ps.close();
}}
action:
package com.Test3.Action;import java.io.UnsupportedEncodingException;
import java.sql.SQLException;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;import com.Test3.dao.test3_dao;
import com.Test3.formbean.test3_1zhuce_form;public class test3_1zhuce_action extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws UnsupportedEncodingException, SQLException {
request.setCharacterEncoding("utf-8");
System.out.println("utf-8");
test3_1zhuce_form user = (test3_1zhuce_form) form;
DataSource ds = this.getDataSource(request);
test3_dao dao = new test3_dao(ds);
dao.user_insert(user);
return mapping.findForward("ok");
}
}请大侠多多指教啊在这里谢谢了。

解决方案 »

  1.   

    好长啊。。
    而且刚开始感觉用mysql简单些~
      

  2.   

    我点击注册按钮后就是404的页面,到数据库里看,数据也没有被插入,另外我想知道在eclipse中如何跟流程呢?我会设置断点,可不会跟踪。对于那种小的application的我会跟,可工程到这种有库的就不知道怎么弄了。
      

  3.   

    <form name="form1" method="post" action="test3_1zhuce">
    楼主应该拿个完整的jsp例子看看改改,不要凭想象
      

  4.   

    好好的改一些action属性值就可以了!!!