mytest SSH之一

       
------------------------------------------/mytest/src/com/test/bean/User.java


package com.test.bean;

public class User {
private int id;
private String firstname;
private String lastname;
private int age;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getFirstname() {
return firstname;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public String getLastname() {
return lastname;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}
}


--------------------------------------------/mytest/src/com/test/bean/User.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.test.bean.User" table="users">
<id name="id" column="id">
<generator class="increment"></generator>
</id>

<property name="firstname" column="firstname"
length="50">
</property>
<property name="lastname" column="lastname"
length="50">
</property>
<property name="age" column="age"></property>

</class>
</hibernate-mapping>

--------------------------------------/mytest/src/com/test/bean/User-user-validation.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
<field name="firstname">
<field-validator type="requiredstring">
<message>required first name</message>
</field-validator>
</field>

<field name="lastname">
<field-validator type="requiredstring">
<message>required last name</message>
</field-validator>
</field>

<field name="age">
<field-validator type="required">
<message>required age</message>
</field-validator>
<field-validator type="int">
<param name="min">1</param>
<param name="max">150</param>
<message>age should be between ${min} and ${max}</message>
</field-validator>
</field>

</validators>


---------------------------------------------------/mytest/src/com/test/dao/UserDAO.java
package com.test.dao;

import java.util.List;

import com.test.bean.User;

public interface UserDAO {
public void save(User user);

public void remove(User user);

public void update(User user);

public User findUserById(int id);

public List<User> findAllUsers();
}


-------------------------------/mytest/src/com/test/dao/impl/UserDAOImpl.java

package com.test.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.test.bean.User;
import com.test.dao.UserDAO;

public class UserDAOImpl extends HibernateDaoSupport implements UserDAO {
@SuppressWarnings("unchecked")
public List<User> findAllUsers() {
String sql="from User user order by user.id desc";
return (List<User>)this.getHibernateTemplate().find(sql);
}

public User findUserById(int id) {
User user=(User)this.getHibernateTemplate().get(User.class, id);
return user;
}

public void remove(User user) {
this.getHibernateTemplate().delete(user);
}

public void save(User user) {
this.getHibernateTemplate().save(user);

}

public void update(User user) {
this.getHibernateTemplate().update(user);

}

}


------------------------------------------/mytest/src/com/test/service/UserService.java
package com.test.service;

import java.io.InputStream;
import java.util.List;

import com.test.bean.User;

public interface UserService {
public List<User> findAll();

public User findById(int id);

public void save(User user);

public void delete(User user);

public void update(User user);
public InputStream getInputStream();
}


--------------------------------------/mytest/src/com/test/service/impl/UserServiceImpl.java


package com.test.service.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.test.bean.User;
import com.test.dao.UserDAO;
import com.test.service.UserService;
import com.test.util.CharacterUtils;

public class UserServiceImpl implements UserService {
private UserDAO userDao;

public UserDAO getUserDao() {
return userDao;
}

public void setUserDao(UserDAO userDao) {
this.userDao = userDao;
}

public void delete(User user) {
this.userDao.remove(user);
}

public List<User> findAll() {

return this.userDao.findAllUsers();
}

public User findById(int id) {

return this.userDao.findUserById(id);
}

public void save(User user) {
this.userDao.save(user);
}

public void update(User user) {
this.userDao.update(user);

}

public InputStream getInputStream() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("sheet1");

HSSFRow row = sheet.createRow(0);

HSSFCell cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("序号");

cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("姓");

cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("名");

cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("年龄");

List<User> list = this.findAll();

for (int i = 0; i < list.size(); ++i)
{
User user = list.get(i);

row = sheet.createRow(i + 1);

cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(i + 1);

cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(user.getFirstname());

cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(user.getLastname());

cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(user.getAge());
}

String fileName=CharacterUtils.getRandomString(10);
fileName=new StringBuffer(fileName).append("xls").toString();
File file = new File(fileName);

try
{
OutputStream os = new FileOutputStream(file);
wb.write(os);
os.close();
}
catch (Exception e)
{
e.printStackTrace();
}

InputStream is = null;
try
{
is = new FileInputStream(file);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}

return is;


}
}


--------------------------------------------------mytest/WebRoot/index.jsp


<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>operation</title>
</head>

<body>

<h1><font color="red">Operation List</font></h1>

<s:a href="save.jsp">Save User</s:a> <br><br><br>

<s:a href="listUser.action">List Users</s:a>


</body>
</html>

------------------------------------------------/mytest/WebRoot/list.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'list.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

<script type="text/javascript">
function del()
{
if(confirm("你真的想删除该记录么?"))
{
return true;
}
return false;
}
</script>

</head>

<body>

<h1><font color="red"><center>Users List</center></font></h1>

<table border="1" width="80%" align="center">

<tr>
<td>序号
</td>

<td>姓
</td>

<td>名
</td>

<td>年龄
</td>

<td>删除
</td>

<td>更新
</td>

</tr>

<s:iterator value="#request.list" id="us">
<tr>
<td><s:property value="#us.id"/>
</td>

<td><s:property value="#us.firstname"/>
</td>

<td><s:property value="#us.lastname"/>
</td>

<td><s:property value="#us.age"/>
</td>

<td><s:a href="deleteUser.action?user.id=%{#us.id}" onclick="return del();">delete</s:a>
</td>

<td><s:a href="updatePUser.action?user.id=%{#us.id}">update</s:a>
</td>



</tr>
</s:iterator>

</table>

<s:a href="index.jsp">Homepage</s:a><br><br>
<s:a href="generateExcel.action">生成excel</s:a>

</body>
</html>

-------------------------------------------------/mytest/WebRoot/save.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>Save User</title>

</head>

<body>

<h1><font color="red">Save User</font></h1>

<s:form action="saveUser">
<s:textfield name="user.firstname" label="%{getText('firstname')}"></s:textfield>
<s:textfield name="user.lastname" label="%{getText('lastname')}"></s:textfield>
<s:textfield name="user.age" label="%{getText('age')}"></s:textfield>
<s:submit></s:submit>

</s:form>

</body>
</html>

------------------------------------------------------/mytest/WebRoot/update.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'update.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>

<h1><font color="red">Update User</font></h1>

<s:form action="updateUser">

<table>
<tr>
<td>
<s:hidden name="user.id" value="%{user.id}"></s:hidden>
</td>
</tr>

<tr>
<td>
<s:textfield name="user.firstname" value="%{user.firstname}" label="%{getText('firstname')}"></s:textfield>
</td>
</tr>

<tr>
<td>
<s:textfield name="user.lastname" value="%{user.lastname}" label="%{getText('lastname')}"></s:textfield>
</td>
</tr>

<tr>
<td>
<s:textfield name="user.age" value="%{user.age}" label="%{getText('age')}"></s:textfield>
</td>
</tr>

<tr>
<td>
<s:submit></s:submit>
</td>
</tr>
</table>

</s:form>

</body>
</html>

------------------------------------------------/mytest/src/struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="user" extends="struts-default">
<action name="saveUser" class="saveUserAction">
<result name="success" type="redirect">listUser.action</result>
<result name="input">/save.jsp</result>
</action>
<action name="listUser" class="listUserAction">
<result>/list.jsp</result>
</action>
<action name="deleteUser" class="removeUserAction">
<result name="success" type="redirect">listUser.action</result>
</action>
<action name="updatePUser" class="updatePUserAction">
<result name="success">/update.jsp</result>
</action>
<action name="updateUser" class="updateUserAction">
<result name="success" type="redirect">listUser.action</result>
<result name="input">/update.jsp</result>
</action>
<action name="generateExcel" class="generateExcelAction">
<result name="success" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="contentDisposition">inline;filename="AllUsers.xls"</param>
<param name="inputName">downloadFile</param>
</result>
</action>
</package>
</struts>
------------------------------------------------/mytest/src/struts.properties

struts.custom.i18n.resources=globalMessages
------------------------------/mytest/src/com/test/action/user/GenerateExcelAction.java

package com.test.action.user;

import java.io.InputStream;

import com.opensymphony.xwork2.ActionSupport;
import com.test.service.UserService;

public class GenerateExcelAction extends ActionSupport
{
private UserService service;

public UserService getService()
{
return service;
}

public void setService(UserService service)
{
this.service = service;
}

public InputStream getDownloadFile()
{
return this.service.getInputStream();
}

@Override
public String execute() throws Exception
{
return SUCCESS;
}
}

--------------------------------------/mytest/src/com/test/action/user/ListUserAction.java

package com.test.action.user;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.test.service.UserService;

public class ListUserAction extends ActionSupport {
private UserService service;

public UserService getService() {
return service;
}

public void setService(UserService service) {
this.service = service;
}

@SuppressWarnings("unchecked")
public String execute() throws Exception
{
Map request = (Map) ActionContext.getContext().get("request");

request.put("list", service.findAll());

return SUCCESS;
}

}

----------------------------------/mytest/src/com/test/action/user/RemoveUserAction.java


package com.test.action.user;

import com.opensymphony.xwork2.ActionSupport;
import com.test.bean.User;
import com.test.service.UserService;

public class RemoveUserAction extends ActionSupport
{
private User user;
private UserService service;

public User getUser()
{
return user;
}
public void setUser(User user)
{
this.user = user;
}
public UserService getService()
{
return service;
}
public void setService(UserService service)
{
this.service = service;
}

@Override
public String execute() throws Exception
{
this.service.delete(user);

return SUCCESS;
}

}

-------------------------------/mytest/src/com/test/action/user/SaveUserAction.java

package com.test.action.user;

import com.opensymphony.xwork2.ActionSupport;
import com.test.bean.User;
import com.test.service.UserService;

public class SaveUserAction extends ActionSupport {

private User user;

private UserService service;

public UserService getService() {
return service;
}

public void setService(UserService service) {
this.service = service;
}


public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public String execute() throws Exception {
this.service.save(this.user);
return "success";

}
}

---------------------------------------/mytest/src/com/test/action/user/UpdatePUserAction.java
package com.test.action.user;

import com.opensymphony.xwork2.ActionSupport;
import com.test.bean.User;
import com.test.service.UserService;

public class UpdatePUserAction extends ActionSupport {
private User user;
private UserService service;

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public UserService getService() {
return service;
}

public void setService(UserService service) {
this.service = service;
}
public String execute(){
user=this.service.findById(user.getId());
return "success";
}

}


--------------------------------------/mytest/src/com/test/action/user/UpdateUserAction.java
package com.test.action.user;

import com.opensymphony.xwork2.ActionSupport;
import com.test.bean.User;
import com.test.service.UserService;

public class UpdateUserAction extends ActionSupport {
private User user;
private UserService service;

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public UserService getService() {
return service;
}

public void setService(UserService service) {
this.service = service;
}

public String execute() {
this.service.update(user);
return "success";
}
}

------------------------------------/mytest/src/com/test/action/user/SaveUserAction-validation.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<!--<validators>
<field name="user.firstname">
<field-validator type="requiredstring">
<message>required first name</message>
</field-validator>
</field>

<field name="user.lastname">
<field-validator type="requiredstring">
<message>required last name</message>
</field-validator>
</field>

<field name="user.age">
<field-validator type="required">
<message>required age</message>
</field-validator>
<field-validator type="int">
<param name="min">1</param>
<param name="max">150</param>
<message>age should be between ${min} and ${max}</message>
</field-validator>
</field>

</validators>-->

<validators>
<field name="user">
<field-validator type="visitor">
<param name="context">user</param>
<param name="appendPrefix">true</param>
<message>user's </message>
</field-validator>
</field>
</validators>

--------------------------------------/mytest/src/com/test/action/user/UpdateUserAction-validation.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<!--<validators>
<field name="user.firstname">
<field-validator type="requiredstring">
<message>required first name</message>
</field-validator>
</field>

<field name="user.lastname">
<field-validator type="requiredstring">
<message>required last name</message>
</field-validator>
</field>

<field name="user.age">
<field-validator type="required">
<message>required age</message>
</field-validator>
<field-validator type="int">
<param name="min">1</param>
<param name="max">150</param>
<message>age should be between ${min} and ${max}</message>
</field-validator>
</field>

</validators>-->

<validators>
<field name="user">
<field-validator type="visitor">
<param name="context">user</param>
<param name="appendPrefix">true</param>
<message>user's </message>
</field-validator>
</field>
</validators>

-----------------------------------------/mytest/WebRoot/WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

</web-app>


---------------------------------------/mytest/WebRoot/WEB-INF/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"></property>
<property name="url" value="jdbc:db2://192.168.25.230:50000/JSAMPLE"></property>
<property name="username" value="zyl"></property>
<property name="password" value="123"></property>
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="30"></property>
<property name="maxWait" value="500"></property>
<property name="defaultAutoCommit" value="true"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/test/bean/User.hbm.xml</value>
</list>
</property>
</bean>
<bean id="userDao" class="com.test.dao.impl.UserDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userService" class="com.test.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="saveUserAction" class="com.test.action.user.SaveUserAction"
scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean id="listUserAction" class="com.test.action.user.ListUserAction"
scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean id="removeUserAction" class="com.test.action.user.RemoveUserAction"
scope="prototype">
<property name="service" ref="userService"></property>
</bean>

<bean id="updatePUserAction" class="com.test.action.user.UpdatePUserAction"
scope="prototype">
<property name="service" ref="userService"></property>
</bean>
<bean id="updateUserAction" class="com.test.action.user.UpdateUserAction" scope="prototype">
<property name="service" ref="userService"></property>
</bean>

<bean id="generateExcelAction" class="com.test.action.user.GenerateExcelAction" scope="singleton">
<property name="service" ref="userService"></property>
</bean>

</beans>


---------------------------------------------------/mytest/WebRoot/WEB-INF/spring.tld
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>

<tlib-version>2.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>spring</short-name>
<uri>http://www.springframework.org/tags</uri>
<description>Spring Framework JSP Tag Library</description>

<tag>
<name>htmlEscape</name>
<tag-class>org.springframework.web.servlet.tags.HtmlEscapeTag</tag-class>
<body-content>JSP</body-content>
<description>
Sets default HTML escape value for the current page.
Overrides a "defaultHtmlEscape" context-param in web.xml, if any.
</description>
<attribute>
<name>defaultHtmlEscape</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<description>Set the default value for HTML escaping, to be put
into the current PageContext.</description>
</attribute>
</tag>

<tag>
<name>escapeBody</name>
<tag-class>org.springframework.web.servlet.tags.EscapeBodyTag</tag-class>
<body-content>JSP</body-content>
<description>
Escapes its enclosed body content, applying HTML escaping and/or JavaScript escaping.
The HTML escaping flag participates in a page-wide or application-wide setting
(i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
</description>
<attribute>
<name>htmlEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set HTML escaping for this tag, as boolean value. Overrides the
default HTML escaping setting for the current page.</description>
</attribute>
<attribute>
<name>javaScriptEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set JavaScript escaping for this tag, as boolean value.
Default is false.</description>
</attribute>
</tag>

<tag>
<name>message</name>
<tag-class>org.springframework.web.servlet.tags.MessageTag</tag-class>
<body-content>JSP</body-content>
<description>
Retrieves the message with the given code, or text if code isn't resolvable.
The HTML escaping flag participates in a page-wide or application-wide setting
(i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
</description>
<attribute>
<name>message</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>A MessageSourceResolvable argument (direct or through JSP EL).
Fits nicely when used in conjunction with Spring's own validation error
classes which all implement the MessageSourceResolvable interface. For
example, this allows you to iterate over all of the errors in a form,
passing each error (using a runtime expression) as the value of this
'message' attribute, thus effecting the easy display of such error
messages.</description>
</attribute>
<attribute>
<name>code</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The code (key) to use when looking up the message.
If code is not provided, the text attribute will be used.</description>
</attribute>
<attribute>
<name>arguments</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set optional message arguments for this tag, as a
(comma-)delimited String (each String argument can contain JSP EL),
an Object array (used as argument array), or a single Object (used
as single argument).</description>
</attribute>
<attribute>
<name>argumentSeparator</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The separator character to be used for splitting the
arguments string value; defaults to a 'comma' (',').</description>
</attribute>
<attribute>
<name>text</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Default text to output when a message for the given code
could not be found. If both text and code are not set, the tag will
output null.</description>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The string to use when binding the result to the page,
request, session or application scope. If not specified, the result
gets outputted to the writer (i.e. typically directly to the JSP).</description>
</attribute>
<attribute>
<name>scope</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The scope to use when exporting the result to a variable.
This attribute is only used when var is also set. Possible values are
page, request, session and application.</description>
</attribute>
<attribute>
<name>htmlEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set HTML escaping for this tag, as boolean value.
Overrides the default HTML escaping setting for the current page.</description>
</attribute>
<attribute>
<name>javaScriptEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set JavaScript escaping for this tag, as boolean value. Default is false.</description>
</attribute>
</tag>

<tag>
<name>theme</name>
<tag-class>org.springframework.web.servlet.tags.ThemeTag</tag-class>
<body-content>JSP</body-content>
<description>
Retrieves the theme message with the given code, or text if code isn't resolvable.
The HTML escaping flag participates in a page-wide or application-wide setting
(i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
</description>
<attribute>
<name>message</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>A MessageSourceResolvable argument (direct or through JSP EL).</description>
</attribute>
<attribute>
<name>code</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The code (key) to use when looking up the message.
If code is not provided, the text attribute will be used.</description>
</attribute>
<attribute>
<name>arguments</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set optional message arguments for this tag, as a
(comma-)delimited String (each String argument can contain JSP EL),
an Object array (used as argument array), or a single Object (used
as single argument).</description>
</attribute>
<attribute>
<name>argumentSeparator</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The separator character to be used for splitting the
arguments string value; defaults to a 'comma' (',').</description>
</attribute>
<attribute>
<name>text</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Default text to output when a message for the given code
could not be found. If both text and code are not set, the tag will
output null.</description>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The string to use when binding the result to the page,
request, session or application scope. If not specified, the result
gets outputted to the writer (i.e. typically directly to the JSP).</description>
</attribute>
<attribute>
<name>scope</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The scope to use when exporting the result to a variable.
This attribute is only used when var is also set. Possible values are
page, request, session and application.</description>
</attribute>
<attribute>
<name>htmlEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set HTML escaping for this tag, as boolean value.
Overrides the default HTML escaping setting for the current page.</description>
</attribute>
<attribute>
<name>javaScriptEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set JavaScript escaping for this tag, as boolean value. Default is false.</description>
</attribute>
</tag>

<tag>
<name>hasBindErrors</name>
<tag-class>org.springframework.web.servlet.tags.BindErrorsTag</tag-class>
<body-content>JSP</body-content>
<description>
Provides Errors instance in case of bind errors.
The HTML escaping flag participates in a page-wide or application-wide setting
(i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
</description>
<variable>
<name-given>errors</name-given>
<variable-class>org.springframework.validation.Errors</variable-class>
</variable>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<description>The name of the bean in the request, that needs to be
inspected for errors. If errors are available for this bean, they
will be bound under the 'errors' key.</description>
</attribute>
<attribute>
<name>htmlEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set HTML escaping for this tag, as boolean value.
Overrides the default HTML escaping setting for the current page.</description>
</attribute>
</tag>

<tag>
<name>nestedPath</name>
<tag-class>org.springframework.web.servlet.tags.NestedPathTag</tag-class>
<body-content>JSP</body-content>
<description>
Sets a nested path to be used by the bind tag's path.
</description>
<variable>
<name-given>nestedPath</name-given>
<variable-class>java.lang.String</variable-class>
</variable>
<attribute>
<name>path</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<description>Set the path that this tag should apply. E.g. 'customer'
to allow bind paths like 'address.street' rather than
'customer.address.street'.</description>
</attribute>
</tag>

<tag>
<name>bind</name>
<tag-class>org.springframework.web.servlet.tags.BindTag</tag-class>
<body-content>JSP</body-content>
<description>
Provides BindStatus object for the given bind path.
The HTML escaping flag participates in a page-wide or application-wide setting
(i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
</description>
<variable>
<name-given>status</name-given>
<variable-class>org.springframework.web.servlet.support.BindStatus</variable-class>
</variable>
<attribute>
<name>path</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<description>The path to the bean or bean property to bind status
information for. For instance account.name, company.address.zipCode
or just employee. The status object will exported to the page scope,
specifically for this bean or bean property</description>
</attribute>
<attribute>
<name>ignoreNestedPath</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set whether to ignore a nested path, if any. Default is to not ignore.</description>
</attribute>
<attribute>
<name>htmlEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set HTML escaping for this tag, as boolean value. Overrides
the default HTML escaping setting for the current page.</description>
</attribute>
</tag>

<tag>
<name>transform</name>
<tag-class>org.springframework.web.servlet.tags.TransformTag</tag-class>
<body-content>JSP</body-content>
<description>
Provides transformation of variables to Strings, using an appropriate
custom PropertyEditor from BindTag (can only be used inside BindTag).
The HTML escaping flag participates in a page-wide or application-wide setting
(i.e. by HtmlEscapeTag or a 'defaultHtmlEscape' context-param in web.xml).
</description>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<description>The value to transform. This is the actual object you want
to have transformed (for instance a Date). Using the PropertyEditor that
is currently in use by the 'spring:bind' tag.</description>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The string to use when binding the result to the page,
request, session or application scope. If not specified, the result gets
outputted to the writer (i.e. typically directly to the JSP).</description>
</attribute>
<attribute>
<name>scope</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The scope to use when exported the result to a variable.
This attribute is only used when var is also set. Possible values are
page, request, session and application.</description>
</attribute>
<attribute>
<name>htmlEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set HTML escaping for this tag, as boolean value. Overrides
the default HTML escaping setting for the current page.</description>
</attribute>
</tag>

</taglib>


-------------------------------------------/mytest/src/com/test/util/CharacterUtils.java
package com.test.util;

import java.util.Random;

public class CharacterUtils {
public static String getRandomString(int length) {


String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random= new Random();
StringBuffer sb=new StringBuffer();
for(int i=0;i<length;++i){
int number = random.nextInt(62);
sb.append(str.charAt(number));
}
return sb.toString();

}
// public static void main(String args[]){
// System.out.println(getRandomString(10));
// }
public static String getRandomString2(int length)
{
Random random = new Random();
StringBuffer sb = new StringBuffer();

for (int i = 0; i < length; ++i)
{
int number = random.nextInt(3);
long result = 0;

switch (number)
{
case 0:
result = Math.round(Math.random() * 25 + 65);
sb.append(String.valueOf((char)result));
break;
case 1:
result = Math.round(Math.random() * 25 + 97);
sb.append(String.valueOf((char)result));
break;
case 2:
sb.append(String.valueOf(new Random().nextInt(10)));
break;
}
}

return sb.toString();
}
}


----------------------------------------------/mytest/src/com/test/util/ToDDL.java
package com.test.util;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class ToDDL {
public static void main(String[] args) {
Configuration configure = new Configuration();
configure.configure("hibernate.cfg.xml");
SchemaExport sc = new SchemaExport(configure);
sc.create(true, true);
}
}


----------------------------------------------/mytest/src/hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="myeclipse.connection.profile">zyl</property>
<property name="connection.url">
jdbc:db2://192.168.25.230:50000/JSAMPLE
</property>
<property name="connection.username">zyl</property>
<property name="connection.password">123</property>
<property name="connection.driver_class">
com.ibm.db2.jcc.DB2Driver
</property>
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<mapping resource="com/test/bean/User.hbm.xml" />

</session-factory>

</hibernate-configuration>


----------------------------------------------/mytest/src/globalMessages_en.properties
firstname=firstname
lastname=lastname
age=age
----------------------------------------------/mytest/src/globalMessages_zh.properties
firstname=\u59D3
lastname=\u540D
age=\u5E74\u9F84

---------------------------------------------/mytest/src/log4j.properties
log4j.rootLogger=ERROR,A1
log4j.appender.A1 = org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.TTCCLayout
---------------------------------------------------------
---------------------------------------------------------------
USERS表
键 名称 数据类型 长度 可空
主键 ID INTEGER 4 否
FIRSTNAME VARCHAR 50 是
LASTNAME VARCHAR 50 是
AGE INTEGER 4 是


------------------------------------------------------------------------------------
文件存放路径

mytest
/mytest/src
com.test.action.user
/mytest/src/com/test/action/user/GenerateExcelAction.java
/mytest/src/com/test/action/user/ListUserAction.java
/mytest/src/com/test/action/user/RemoveUserAction.java
/mytest/src/com/test/action/user/SaveUserAction.java
/mytest/src/com/test/action/user/UpdatePUserAction.java
/mytest/src/com/test/action/user/UpdateUserAction.java
/mytest/src/com/test/action/user/SaveUserAction-validation.xml
/mytest/src/com/test/action/user/UpdateUserAction-validation.xml
com.test.bean
/mytest/src/com/test/bean/User.java
/mytest/src/com/test/bean/User-user-validation.xml
/mytest/src/com/test/bean/User.hbm.xml
com.test.dao
/mytest/src/com/test/dao/UserDAO.java
com.test.dao.impl
/mytest/src/com/test/dao/impl/UserDAOImpl.java
com.test.service
/mytest/src/com/test/service/UserService.java
com.test.service.impl
/mytest/src/com/test/service/impl/UserServiceImpl.java
com.test.util
/mytest/src/com/test/util/CharacterUtils.java
/mytest/src/com/test/util/ToDDL.java
/mytest/src/globalMessages_en.properties
/mytest/src/globalMessages_zh.properties
/mytest/src/hibernate.cfg.xml
/mytest/src/log4j.properties
/mytest/src/struts.properties
/mytest/src/struts.xml
/mytest/WebRoot
/mytest/WebRoot/META-INF
/mytest/WebRoot/META-INF/MANIFEST.MF
/mytest/WebRoot/WEB-INF
/mytest/WebRoot/WEB-INF/lib
/mytest/WebRoot/WEB-INF/applicationContext.xml
/mytest/WebRoot/WEB-INF/spring-form.tld
/mytest/WebRoot/WEB-INF/spring.tld
/mytest/WebRoot/WEB-INF/web.xml
/mytest/WebRoot/index.jsp
/mytest/WebRoot/list.jsp
/mytest/WebRoot/save.jsp
/mytest/WebRoot/update.jsp
------------------------------------------------------------------
所需的包
/mytest/WebRoot/WEB-INF/lib/antlr-2.7.6.jar
/mytest/WebRoot/WEB-INF/lib/aopalliance.jar
/mytest/WebRoot/WEB-INF/lib/asm-attrs.jar
/mytest/WebRoot/WEB-INF/lib/asm-commons-2.2.3.jar
/mytest/WebRoot/WEB-INF/lib/asm-util-2.2.3.jar
/mytest/WebRoot/WEB-INF/lib/asm.jar
/mytest/WebRoot/WEB-INF/lib/aspectjrt.jar
/mytest/WebRoot/WEB-INF/lib/aspectjweaver.jar
/mytest/WebRoot/WEB-INF/lib/c3p0-0.9.1.2.jar
/mytest/WebRoot/WEB-INF/lib/cglib-2.1.3.jar
/mytest/WebRoot/WEB-INF/lib/cglib-nodep-2.1_3.jar
/mytest/WebRoot/WEB-INF/lib/commons-attributes-api.jar
/mytest/WebRoot/WEB-INF/lib/commons-attributes-compiler.jar
/mytest/WebRoot/WEB-INF/lib/commons-codec.jar
/mytest/WebRoot/WEB-INF/lib/commons-collections-2.1.1.jar
/mytest/WebRoot/WEB-INF/lib/commons-dbcp.jar
/mytest/WebRoot/WEB-INF/lib/commons-fileupload.jar
/mytest/WebRoot/WEB-INF/lib/commons-httpclient.jar
/mytest/WebRoot/WEB-INF/lib/commons-io.jar
/mytest/WebRoot/WEB-INF/lib/commons-lang.jar
/mytest/WebRoot/WEB-INF/lib/commons-logging-1.0.4.jar
/mytest/WebRoot/WEB-INF/lib/commons-logging.jar
/mytest/WebRoot/WEB-INF/lib/commons-pool.jar
/mytest/WebRoot/WEB-INF/lib/cos.jar
/mytest/WebRoot/WEB-INF/lib/dom4j-1.6.1.jar
/mytest/WebRoot/WEB-INF/lib/ehcache-1.2.3.jar
/mytest/WebRoot/WEB-INF/lib/ejb3-persistence.jar
/mytest/WebRoot/WEB-INF/lib/freemarker-2.3.15.jar
/mytest/WebRoot/WEB-INF/lib/freemarker.jar
/mytest/WebRoot/WEB-INF/lib/hibernate-annotations.jar
/mytest/WebRoot/WEB-INF/lib/hibernate-commons-annotations.jar
/mytest/WebRoot/WEB-INF/lib/hibernate-entitymanager.jar
/mytest/WebRoot/WEB-INF/lib/hibernate-validator.jar
/mytest/WebRoot/WEB-INF/lib/hibernate3.jar
/mytest/WebRoot/WEB-INF/lib/itext-1.3.jar
/mytest/WebRoot/WEB-INF/lib/jaas.jar
/mytest/WebRoot/WEB-INF/lib/jakarta-oro-2.0.8.jar
/mytest/WebRoot/WEB-INF/lib/jasperreports-1.3.4.jar
/mytest/WebRoot/WEB-INF/lib/javassist.jar
/mytest/WebRoot/WEB-INF/lib/jaxen-1.1-beta-7.jar
/mytest/WebRoot/WEB-INF/lib/jboss-archive-browsing.jar
/mytest/WebRoot/WEB-INF/lib/jdbc2_0-stdext.jar
/mytest/WebRoot/WEB-INF/lib/jotm.jar
/mytest/WebRoot/WEB-INF/lib/jta.jar
/mytest/WebRoot/WEB-INF/lib/jxl.jar
/mytest/WebRoot/WEB-INF/lib/log4j-1.2.11.jar
/mytest/WebRoot/WEB-INF/lib/log4j-1.2.14.jar
/mytest/WebRoot/WEB-INF/lib/mysql-connector-java-5.0.3-bin.jar
/mytest/WebRoot/WEB-INF/lib/ognl-2.7.3.jar
/mytest/WebRoot/WEB-INF/lib/persistence.jar
/mytest/WebRoot/WEB-INF/lib/poi-2.5.1.jar
/mytest/WebRoot/WEB-INF/lib/portlet-api.jar
/mytest/WebRoot/WEB-INF/lib/spring-agent.jar
/mytest/WebRoot/WEB-INF/lib/spring-aop.jar
/mytest/WebRoot/WEB-INF/lib/spring-beans.jar
/mytest/WebRoot/WEB-INF/lib/spring-context.jar
/mytest/WebRoot/WEB-INF/lib/spring-core.jar
/mytest/WebRoot/WEB-INF/lib/spring-dao.jar
/mytest/WebRoot/WEB-INF/lib/spring-hibernate3.jar
/mytest/WebRoot/WEB-INF/lib/spring-ibatis.jar
/mytest/WebRoot/WEB-INF/lib/spring-jdbc.jar
/mytest/WebRoot/WEB-INF/lib/spring-jdo.jar
/mytest/WebRoot/WEB-INF/lib/spring-jpa.jar
/mytest/WebRoot/WEB-INF/lib/spring-portlet.jar
/mytest/WebRoot/WEB-INF/lib/spring-struts.jar
/mytest/WebRoot/WEB-INF/lib/spring-tomcat-weaver.jar
/mytest/WebRoot/WEB-INF/lib/spring-toplink.jar
/mytest/WebRoot/WEB-INF/lib/spring-web.jar
/mytest/WebRoot/WEB-INF/lib/spring-webmvc.jar
/mytest/WebRoot/WEB-INF/lib/struts.jar
/mytest/WebRoot/WEB-INF/lib/struts2-core-2.1.8.jar
/mytest/WebRoot/WEB-INF/lib/struts2-spring-plugin-2.1.8.jar
/mytest/WebRoot/WEB-INF/lib/velocity-1.5.jar
/mytest/WebRoot/WEB-INF/lib/velocity-tools-view-1.3.jar
/mytest/WebRoot/WEB-INF/lib/xapool.jar
/mytest/WebRoot/WEB-INF/lib/xerces-2.6.2.jar
/mytest/WebRoot/WEB-INF/lib/xml-apis.jar
/mytest/WebRoot/WEB-INF/lib/xwork-core-2.1.6.jar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值