Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > 简单的struts应用开发(2)
【标  题】:简单的struts应用开发(2)
【关键字】:应用,struts,str,struts
【来  源】:网络

简单的struts应用开发(2)

Your Ad Here 简单的struts应用开发(2)

第二步: 配置数据库

1.首先创建数据联接bean, 并打包到 ConnectionPool, 它将从我们配置的联接池中取得可用联接.

// Java Document
package ConnectionPool;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
import java.io.*;
import java.util.*;

public class getDbConnection {

Connection conn;
Statement stmt;
ResultSet rs=null;

String foo = "Not Connected";
int bar = -1;

public getDbConnection() {
try{
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");

DataSource ds =
(DataSource)ctx.lookup(
"java:comp/env/jdbc/TestDB");

if (ds != null) {
conn = ds.getConnection();

}
}
catch(Exception e) {
e.printStackTrace();
}
}

public Connection getCon()
{
return conn;
}


public void d_close() throws SQLException
{
if (rs != null) {
try { rs.close(); } catch (SQLException e) { ; }
rs = null;
}
if (stmt != null) {
try { stmt.close(); } catch (SQLException e) { ; }
stmt = null;
}
if (conn != null) {
try { conn.close(); } catch (SQLException e) { ; }
conn = null;
}

}

protected void finalize() throws Throwable
{
try { d_close(); } catch (SQLException e) { ; }
}

}

2.创建数据库.

数据库名: mystruts

部门表: mydep

_______________________________________
dep_id dep_name
_______________________________________
1 dep1
2 dep2
3 dep3
4 dep4
_______________________________________

用户表: myuser
______________________________________________
user_id user_name dep tel
______________________________________________
1 jack 1 0769-2454042
2 max 2 0769-2454043
______________________________________________

(注: 以上字段为了测试方便. 全部使用字符型)


第三步: 创建ActionForm (userActionForm.java)

package mystruts; //请打包到mystruts下.

import org.apache.struts.action.*;
import javax.servlet.http.*;

public class userActionForm extends ActionForm {
private String action="add";
private String dep;
private String tel;
private String user_id;
private String user_name;
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getDep() {
return dep;
}
public void setDep(String dep) {
this.dep = dep;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {

return null;
}
public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
}
} (未完待续)
简单的struts应用开发(3):【上一篇】
简单的struts应用开发(1):【下一篇】
【相关文章】
  • 简单的struts应用开发(3)
  • 简单的struts应用开发(4)
  • 在Eclipse3.0.x配置基于STRUTS的WEB开发环境
  • Struts学习笔记
  • 通过开发一个STRUTS项目的体会
  • Struts Controller
  • 关于struts的文本域
  • struts构建文件上传(1)
  • struts构建文件上传(2)
  • 浅析Struts 体系结构与工作原理(2)
  • 【随机文章】
  • 公安军队VPN
  • 瞬间搞定百台Windows升级(update)
  • TEW-410APB 54Mbps 802.11g无线接入点+网桥
  • Alexa排名新高-升1,338位(手机网址之家,www.mobi123.cn)
  • OSPF與ISIS的雙向重分布
  • Venus 6.1a With Full Source For D6/CB6
  • 在linux7.1上安装jdk+tomcat+oracle9i笔记
  • 真难!
  • DS6800连接AIX时vpath常见问题解答
  • Winrar自动备份
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.