commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.1.jar
freemarker-2.3.13.jar
ognl-2.6.11.jar
struts2-core-2.1.6.jar
xwork-2.1.2.jar
以下是csdn下的下载链接:
http://download.csdn.net/source/2907435
posted @ 2010-12-15 09:44 jack zhai 阅读(170) | 评论 (0) | 编辑 收藏
包括:
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
ejb3-persistence.jar
hibernate3.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
javassist-3.9.0.GA.jar
jta-1.1.jar
slf4j-api-1.5.8.jar
slf4j-nop-1.5.8.jar
在csdn上的下载地址:
http://download.csdn.net/source/2907437
posted @ 2010-12-15 09:43 jack zhai 阅读(181) | 评论 (0) | 编辑 收藏
<package name="member" namespace="/member" extends="struts-default"> <action name="regist" class="cc.apl330.action.MemberAction"> <result >/suc.jsp</result> <result name="isExists">/fail.jsp</result> </action> </package>
运行正常,用户注册成功后会跳转到suc.jsp
如果将配置改成
<package name="member" namespace="/member" extends="struts-default"> <action name="regist" class="cc.apl330.action.MemberAction"> <result >/suc.html</result> <result name="isExists">/fail.jsp</result> </action> </package>
运行不正常,用户输入数据后,点击确定。查看数据库,数据库写入正常,但页面空白,地址栏却正常:http://localhost:8080/test/member/regist
posted @ 2010-12-14 10:58 jack zhai 阅读(143) | 评论 (0) | 编辑 收藏
1、导入spring 及Mysql's jdbc包2、代码的输入
AOP类package cc.apl330.aspect; public class UserAspect { public void before() { System.out.println("method before!"); } }
数据库操作package cc.apl330.dao; import cc.apl330.model.User; public interface IDAO { public void save(User user) ; }
数据库操作package cc.apl330.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import javax.sql.DataSource; import cc.apl330.model.User; public class UserDAO implements IDAO { private DataSource dataSource ; public void save(User user) { int id = user.getId(); String name = user.getName() ; String sql = "INSERT INTO USER(_id,_name) VALUE(?,?)" ; Connection conn = null ; PreparedStatement ps = null ; try { conn = dataSource.getConnection() ; ps = conn.prepareStatement(sql) ; ps.setInt(1, id) ; ps.setString(2, name) ; ps.executeUpdate() ; } catch (SQLException e) { e.printStackTrace(); }finally{ try { ps.close() ; conn.close() ; } catch (SQLException e) { e.printStackTrace(); } } } public DataSource getDataSource() { return dataSource; } public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } }
业务层package cc.apl330.service; import cc.apl330.dao.IDAO; import cc.apl330.dao.UserDAO; import cc.apl330.model.User; public class UserService { private UserDAO userdao = null ; public void add(User user) { userdao.save(user) ; } public UserDAO getUserdao() { return userdao; } public void setUserdao(UserDAO userdao) { this.userdao = userdao; } }
测试类package cc.apl330.service; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import cc.apl330.model.User; public class UserServiceTest { @Test public void save() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml") ; UserService userService = (UserService) ctx.getBean("userService"); User user = new User() ; user.setName("apl330") ; userService.add(user); } }
sping配置文件<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <bean id="dao" class="cc.apl330.dao.UserDAO" > <property name="dataSource" ref="dataSource"></property> </bean> <bean id="user" class="cc.apl330.model.User" scope="prototype"></bean> <bean id="userService" class="cc.apl330.service.UserService"> <property name="userdao" ref="dao"></property> </bean> <bean id="addbefore" class="cc.apl330.aspect.UserAspect"></bean> <aop:config> <aop:pointcut expression="execution(public * cc.apl330.service.*.add(..))" id="userpoincut"/> <aop:aspect id="useraspect" ref="addbefore" > <aop:before method="before" pointcut-ref="userpoincut"/> </aop:aspect> </aop:config> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/spring"></property> <property name="username" value="root"></property> <property name="password" value="359848184"></property> </bean> </beans>
posted @ 2010-12-11 19:09 jack zhai 阅读(345) | 评论 (0) | 编辑 收藏
一、编写Servlet代码,继承自HttpServlet类,并覆盖 public void doGet(HttpServletRequest req, HttpServletResponse resp) 方法
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class SimpleHello extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter out = resp.getWriter() ; out.println("hello world"); out.close() ; } }
二、部署Servlet。在web.xml中加入如下代码:
<servlet> <servlet-name>SimpleHello</servlet-name> <servlet-class>cc.apl330.SimpleHello</servlet-class> </servlet> <servlet-mapping> <servlet-name>SimpleHello</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping>
三、测试。在浏览器中输入:http://localhost:8080/ServletTest/hello
服务器过程是这样的:1 服务器检测请求地址:http://localhost:8080/ServletTest/hello2 得到字符串: /hello3 在web.xml中寻找 <servlet-mapping>下的<url-pattern>内的值是否有对应的。有,就找到<servlet-name>的值4 在web.xml中寻找 <servlet> 找到相应的servlet类执行
posted @ 2010-09-30 10:40 jack zhai 阅读(81) | 评论 (0) | 编辑 收藏
erji2.jsp 文件
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@page import="cc.apl330.Citys_Arr"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'erji2.jsp' starting page</title> </head> <!-- init()用于初始化联动选项 --> <body onload="init()"> <% //读取数据 Citys_Arr ca = null ; %> <form action="" name="fom"> <select name="s1" onchange="sel()"> <% ca = new Citys_Arr() ; for(int i = 0 ; i < ca.getCitys().length; i++ ) { %> <option><%=ca.getCitys()[i]%></option> <% } %> </select> <select name="s2"> </select> </form> </body> <script type="text/javascript"> <% int citys = ca.getCitys().length ; %> var select2 = new Array(<%=citys%>) ; <!-- //初始化 --> function init() { <% for(int i = 0 ; i < citys ; i++ ) { %> select2[<%=i%>] = new Array() ; <% } %> <% for(int x = 0 ; x < citys ;x++){ for(int y = 0 ; y < ca.getZone()[u].length ; y++){ %> select2[<%=x%>][<%=y%>] = new Option("<%=ca.getZone()[x][y]%>" , "<%=ca.getZone()[x][y]%>"); <% } } %> } <!-- //根据前一项选择加载联动数据 --> function sel() { var pp = document.fom.s1.options.selectedIndex ; var temp = document.fom.s2; for (i = 0; i < select2[pp].length; i++) { temp.options[i] = new Option(select2[pp][i].text, select2[pp][i].value); } temp.options[0].selected = true; } </script> </html>
Citys_Arr.java //用于读取数据
package cc.apl330; public class Citys_Arr { private String[] citys = {"桂林","崇左"} ; private String[][] zone = { {"平乐","临桂","荔浦","二塘"}, {"龙州","天等","花山","乐一"} } ; public String[] getCitys() { return citys; } public void setCitys(String[] citys) { this.citys = citys; } public String[][] getZone() { return zone; } public void setZone(String[][] zone) { this.zone = zone; } }
posted @ 2010-09-30 10:36 jack zhai 阅读(104) | 评论 (0) | 编辑 收藏
1)将公共操作和域放置在超类
2)不要使用受保护的域
3)使用继承实现“is-a”关系
4)除非所有继承的方法都有意义,否则不要使用继承
5)在覆盖方法的时候,不要心迹预期的行为
6)使用多态,而非类型信息
7)不要过多地使用反射
posted @ 2010-08-23 12:39 jack zhai 阅读(147) | 评论 (0) | 编辑 收藏
public class Person{ public static void main(String[] args) { Person p1 = new Person("p1","femail",15) ; Person p2 = new Person("p","mail", 20) ; Person p3 = new Person("p","mail", 20) ; System.out.println(p1.equals(p2)) ; System.out.println(p3.equals(p2)) ; } public Person() {} ; public Person(String name, String sex, int age) { super(); this.name = name; this.sex = sex; this.age = age; } public boolean equals(Object otherObject) { //检测两个引用是否指向同一对象 if( this == otherObject ) return true ; //检测otherObject是否为空 if( null == otherObject) return false ; //检测是否为同一个类 if( getClass() != otherObject.getClass() ) return false ; //将otherObject转成Person类 Person person = (Person)otherObject ; return this.getName().equals(person.getName()) && this.getSex().equals(person.getSex()) && this.getAge() == person.getAge() ; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String name = null; public String sex = null ; public int age = 0 ; }
posted @ 2010-08-16 23:34 jack zhai 阅读(107) | 评论 (0) | 编辑 收藏
equals方法具有以下特性:
1)自反性:对于任何非空引用 x ,x.equals(x) 应该返回 true。
2)对称性:对于任何引用 x 和 y ,如果 x.equals(y)返回 true ,那么 y.equals(x) 也应该返回 true 。
3)传递性:对于任何引用 x 、y 和 z ,如果 x.equals(y) 返回 true ,y.equals(z) 返回 true ,那么 x.equals(z) 就应该返回 true 。
4)一致性:如果 x 和 y 引用的对象没有发生变化,那么反复调用 x.equals(y) 应该返回同样的结果。
5)对于任意非空引用 x ,x.equals(null) 应该返回false 。
posted @ 2010-08-16 21:18 jack zhai 阅读(179) | 评论 (0) | 编辑 收藏
次序为:
1、static块内代码
2、自上而下的运行代码
3、在try{}catch(){}finally{}内,在try{}内遇到return关键字的时候,就马上跳到finally块内执行。
4、执行完毕finally{}块后就执行刚才的return语句
注意:finally内有return后,方法的其他地方就不能存在return。
public class Main { static{ System.out.println("static"); } public int test(){ try{ System.out.println("try") ; return 1 ; }catch(Exception e){ System.out.println(e.getMessage()) ; }finally{ System.out.println("finally") ; } return 3 ; } public static void main(String[] args) { int i = new Main().test() ; System.out.println("test:" + i ); } }
输出结果为:
statictryfinallytest:1
posted @ 2010-08-09 10:11 jack zhai 阅读(207) | 评论 (5) | 编辑 收藏
Powered by: BlogJava Copyright © jack zhai