Struts第二天总结案例(二)

2014-11-24 11:52:21 · 作者: · 浏览: 27
ctionSupport{
121
122 //封装请求的参数,必须与jsp页面中的input标签的username名字相同
123 private String username;
124 private String password;
125 private User entity;
126 //set方法用于获取jsp页面传过来的参数
127 public void setUsername(String username) {
128 this.username = username;
129 }
130 public void setPassword(String password) {
131 this.password = password;
132 }
133 public User getEntity() {
134 return entity;
135 }
136
137 //get方法用于从action中获取值传到web的jsp页面输出
138 /* public String getUsername() {
139 return username;
140 }*/
141
142
143 public String login(){
144 ActionDao dao = new ActionDao();
145 try {
146 entity = dao.login(username,password);
147 } catch (SQLException e) {
148 e.printStackTrace();
149 }
150 if(entity != null){
151 return SUCCESS;
152 }else{
153 return LOGIN;
154 }
155 }
156 public String execute(){
157 System.out.println("处理中。。。。。。");
158 return SUCCESS;
159 }
160 }
161 6.util工具类
162 package com.csdn.util;
163
164 import java.sql.Connection;
165 import java.sql.SQLException;
166 import javax.sql.DataSource;
167 import com.mchange.v2.c3p0.ComboPooledDataSource;
168 www.2cto.com
169 public class DBManager {
170 private static ComboPooledDataSource ds = null;
171 static{
172 //这里要注意的是:xml配置文件的名字一定要是c3p0-config.xml,可以doc参考帮助,帮助中有命名,如果名字写错了会无法加载驱动,空指针的错
173 ds = new ComboPooledDataSource("mysql");
174 }
175 public static Connection getCon() throws SQLException{
176 return ds.getConnection();
177 }
178 public static DataSource getDataSource(){
179 return ds;
180 }
181 }