簡易構築sshフレームワーク
プロファイル:
1.struts.xml
web.xml
3.applicationContext.xml
4.actionクラス:
全体の工事のソースコードを添付して、もし必要があればダウンロードすることができて、时间の原因のため、プログラムの中でどうしても不足があって、みんなの指摘を忘れて、共に进歩します!thank you!
1.struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.Factory" value="spring"></constant>
<package name="com.taoge.action" extends="struts-default" namespace="/taoge">
<action name="findall" class="testBean">
<result>/success.jsp</result>
</action>
<action name="save" class="testBean" method="save">
<result name="SUCCESS">/success.jsp</result>
<result name="save">/error.jsp</result>
</action>
</package>
<package name="ajax_action" extends="json-default" namespace="/">
<action name="ajax_*" class="testBean" method="{1}">
<result type="json" ></result>
</action>
</package>
</struts>
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">
<display-name></display-name>
<context-param>
<param-name></param-name>
<param-value></param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<!-- session -->
<filter>
<filter-name>lazyLoadingFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<!--
org.springframework.orm.hibernate3.LocalSessionFactoryBean
spring , sessionFactory.
LocalSessionFactoryBean spring sessionFactory,
, sessionFactory
-->
<param-name>sessionFactory</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
<!-- Spring Listener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- Log4j Config -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>lazyLoadingFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>
com.taoge.filter.FilterEncoding
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
3.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"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass"
value="com.mysql.jdbc.Driver">
</property>
<property name="jdbcUrl" value="jdbc:mysql://116.255.144.155:58586/360_dflq_accounts"></property>
<property name="user" value="rylq_admin"></property>
<property name="password" value="rylq_210621047"></property>
<!-- .-->
<property name="minPoolSize">
<value>5</value>
</property>
<!-- 。Default: 15 -->
<property name="maxPoolSize">
<value>30</value>
</property>
<!-- , minPoolSize maxPoolSize 。Default: 3 -->
<property name="initialPoolSize">
<value>10</value>
</property>
<!-- ,60 。 0 。Default: 0 -->
<property name="maxIdleTime">
<value>60</value>
</property>
<!-- c3p0 。Default: 3 -->
<property name="acquireIncrement">
<value>5</value>
</property>
<!-- JDBC , PreparedStatements 。 statements
connection 。 。
maxStatements maxStatementsPerConnection 0, 。Default: 0 -->
<property name="maxStatements">
<value>0</value>
</property>
<!-- 60 。Default: 0 -->
<property name="idleConnectionTestPeriod">
<value>60</value>
</property>
<!-- 。Default: 30 -->
<property name="acquireRetryAttempts">
<value>30</value>
</property>
<!-- 。
, getConnection() 。 true,
。Default: false-->
<property name="breakAfterAcquireFailure">
<value>true</value>
</property>
<!-- 。 true connection
。 idleConnectionTestPeriod automaticTestTable
。Default: false -->
<property name="testConnectionOnCheckout">
<value>false</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/taoge/model/Account.hbm.xml</value>
<value>com/taoge/model/Notice.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
</props>
</property>
</bean>
<bean id="stuDao" class="com.taoge.dao.hibernate3.stuHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="stuManager" class="com.taoge.service.Imp.stuManagerImpl">
<property name="stuDao">
<ref bean="stuDao"/>
</property>
</bean>
<bean id="testBean" class="com.taoge.action.stuAction" scope="prototype">
<property name="stuManager">
<ref bean="stuManager"/>
</property>
<property name="noticeDAO">
<ref bean="noticeDAO"/>
</property>
</bean>
<bean id="noticeDAO" class="com.taoge.model.NoticeDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean></beans>
4.actionクラス:
package com.taoge.action;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import net.sf.json.JSONObject;
import com.opensymphony.xwork2.ActionSupport;
import com.taoge.model.Account;
import com.taoge.model.Notice;
import com.taoge.model.NoticeDAO;
import com.taoge.service.stuManager;
@Entity
public class stuAction extends ActionSupport {
/**
*
*/
@Id
@GeneratedValue
private static final long serialVersionUID = 1L;
@ManyToOne
private stuManager stuManager;
private NoticeDAO noticeDAO;
public void setNoticeDAO(NoticeDAO noticeDAO) {
this.noticeDAO = noticeDAO;
}
private List list;
private String str="haha";
private String result;
private Notice noticeBean;
private String haha;
private String command;
private String username;
private String password;
private Account user = null;
private Account users;
public String add(Object obj){
stuManager.add(obj);
return SUCCESS;
}
public String login2(){
System.out.println(user.getUsername()+":"+user.getPassword()+" :"+this.getHaha());
String rslt=this.getResult();
noticeBean = (Notice)JSONObject.toBean(JSONObject.fromObject(rslt), Notice.class);
// Account account=new Account();
//
// account.setUsername(user.getUsername());
// account.setPassword(user.getPassword());
this.setUsers(user);
list = noticeDAO.findAll();
this.setCommand("success123");
// return "login2";
return SUCCESS;
}
/*
*
*/
// public String login(){
//
// System.out.println(user.getUsername()+":"+user.getPassword());
//
// Map<String, String> map = new HashMap<String, String>();
//
// map.put("name", user.getUsername());
//
// map.put("password",user.getPassword());
//
// list = stuManager.getList();
//
//
//// JSONObject obj = JSONObject.fromObject(map);
//// result = obj.toString();
//
// JSONArray jsonarray = JSONArray.fromObject(list);
////
//// result = jsonarray.toString();
//
// ActionContext context = ActionContext.getContext();
//// HttpServletRequest request=(HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);
//
// HttpServletResponse rspon = (HttpServletResponse) context.get(ServletActionContext.HTTP_RESPONSE);
//
// System.out.println("result:"+result);
//
// rspon.setCharacterEncoding("utf-8");
// rspon.setCharacterEncoding("utf-8");
// rspon.setContentType("text/html");
//
// PrintWriter out = null;
// try {
// out = rspon.getWriter();
// } catch (IOException e) {
//
// e.printStackTrace();
// }
//
//
// out.print(jsonarray);
//
// out.flush();
// out.close();
//
// return SUCCESS;
// }
public String save(){
// System.out.println("haha"+username);
System.out.println(user.getUsername()+":"+user.getPassword());
list = stuManager.getList();
return SUCCESS;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getHaha() {
return haha;
}
public void setHaha(String haha) {
this.haha = haha;
}
public String getCommand() {
return command;
}
public void setCommand(String command) {
this.command = command;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public Account getUsers() {
return users;
}
public void setUsers(Account users) {
this.users = users;
}
public Account getUser() {
return user;
}
public void setUser(Account user) {
this.user = user;
}
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
public void setStuManager(stuManager stuManager) {
this.stuManager = stuManager;
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public Notice getNoticeBean() {
return noticeBean;
}
public void setNoticeBean(Notice noticeBean) {
this.noticeBean = noticeBean;
}
}
全体の工事のソースコードを添付して、もし必要があればダウンロードすることができて、时间の原因のため、プログラムの中でどうしても不足があって、みんなの指摘を忘れて、共に进歩します!thank you!