search
HomeDatabaseMysql Tutorialmysql+ssh调整例子,附源码下载

mysql+ssh整合例子,附源码下载 项目引用jar下载:http://download.csdn.net/detail/adam_zs/7262727 项目源码下载地址:http://download.csdn.net/detail/adam_zs/7262749 今天花时间把ssh整合了一下,重新再学习一下,希望对大家有所帮助! 我用的是mysql数

mysql+ssh整合例子,附源码下载

项目引用jar下载:http://download.csdn.net/detail/adam_zs/7262727

项目源码下载地址:http://download.csdn.net/detail/adam_zs/7262749

今天花时间把ssh整合了一下,重新再学习一下,希望对大家有所帮助!

我用的是mysql数据库,建表语句比较简单就不贴出来了,建表的时候记的设置id为自动增加哦。

项目文件位置,项目引用jar包


项目配置文件

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">
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>

	<!-- 使用ContextLoaderListener初始化Spring容器 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<!-- 定义Struts2的FilterDispathcer的Filter -->
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
	</filter>
	<!-- FilterDispatcher用来初始化Struts2并且处理所有的WEB请求。 -->
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<struts>
	<!-- 配置了系列常量 -->
	<constant name="struts.i18n.encoding" value="UTF-8"></constant>

	<package name="wangzs" extends="struts-default">
		<action name="login" class="loginAction">
			<result name="error">/error.jsp</result>
			<result name="success">/welcome.jsp</result>
		</action>
		<!-- 让用户直接访问该应用时列出所有视图页面 -->
		<action name="">
			<result>.</result>
		</action>
	</package>
</struts>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans>

	<!-- 定义数据源Bean,使用C3P0数据源实现 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
		<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
		<property name="jdbcUrl" value="jdbc:mysql://localhost/test"></property>
		<property name="user" value="root"></property>
		<property name="password" value="wzs_626750095"></property>
		<property name="maxPoolSize" value="40"></property>
		<property name="minPoolSize" value="1"></property>
		<property name="initialPoolSize" value="1"></property>
		<property name="maxIdleTime" value="20"></property>
	</bean>

	<!-- 定义Hibernate的SessionFactory -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<!-- mappingResouces属性用来列出全部映射文件 -->
		<property name="mappingResources">
			<list>
				<value>com/wzs/bean/Person.hbm.xml</value>
			</list>
		</property>
		<!-- 定义Hibernate的SessionFactory的属性 -->
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.MySQLInnoDBDialect</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">true</prop>
			</props>
		</property>
	</bean>

	<bean id="loginAction" class="com.wzs.action.LoginAction" scope="prototype">
		<property name="ms" ref="myService"></property>
	</bean>
	<bean id="myService" class="com.wzs.service.impl.MyServiceImpl">
		<property name="personDao" ref="personDao"></property>
	</bean>
	<bean id="personDao" class="com.wzs.dao.impl.PersonDaoImpl">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
</beans>

java代码

Person.java

package com.wzs.bean;

public class Person {
	private Integer id;
	private String name;
	private String password;

	public Integer getId() {
		return id;
	}

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

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}

Person.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>

<hibernate-mapping package="lee">
	<class name="com.wzs.bean.Person" table="Person">
		<!-- 映射标识属性 -->
		<id name="id" type="int" column="id">
			<generator class="identity"></generator>
		</id>
		<!-- 映射普通属性 -->
		<property name="name" type="string" column="name"></property>
		<property name="password" type="string" column="password"></property>
	</class>
</hibernate-mapping>

LoginAction.java

package com.wzs.action;

import com.opensymphony.xwork2.ActionSupport;
import com.wzs.service.MyService;

@SuppressWarnings("serial")
public class LoginAction extends ActionSupport {
	// 下面是用于封装用户请求参数的两个属性
	private String name;
	private String password;
	// 用于封装处理结果的属性
	private String tip;
	// 系统所用的业务逻辑组件
	private MyService ms;

	// 设置注入业务逻辑组件所必需的setter方法
	public void setMs(MyService ms) {
		this.ms = ms;
	}

	/**
	 * 用户登录
	 * 
	 * @return
	 * @throws Exception
	 */
	public String login() throws Exception {
		// 调用业务逻辑组件的valid方法来
		// 验证用户输入的用户名和密码是否正确
		if (ms.valid(getName(), getPassword())) {
			setTip("哈哈,整合成功!");
			return SUCCESS;
		} else {
			return ERROR;
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getTip() {
		return tip;
	}

	public void setTip(String tip) {
		this.tip = tip;
	}

	public MyService getMs() {
		return ms;
	}

}

MyService.java

package com.wzs.service;

public interface MyService {
	/**
	 * 校验用户名密码
	 * 
	 * @param name
	 *            用户名
	 * @param password
	 *            密码
	 * @return true:存在,false:不存在
	 */
	boolean valid(String name, String password);
}

MyServiceImpl.java

package com.wzs.service.impl;

import com.wzs.dao.PersonDao;
import com.wzs.service.MyService;

public class MyServiceImpl implements MyService {

	private PersonDao personDao;

	/**
	 * 校验用户名密码
	 * 
	 * @param name
	 *            用户名
	 * @param password
	 *            密码
	 * @return true:存在,false:不存在
	 */
	public boolean valid(String name, String password) {
		return personDao.valid(name, password);
	}

	public PersonDao getPersonDao() {
		return personDao;
	}

	public void setPersonDao(PersonDao personDao) {
		this.personDao = personDao;
	}

}

PersonDao.java

package com.wzs.dao;

import java.util.List;

import com.wzs.bean.Person;

public interface PersonDao {

	/**
	 * 校验用户名密码
	 * 
	 * @param name
	 *            用户名
	 * @param password
	 *            密码
	 * @return true:存在,false:不存在
	 */
	public boolean valid(String name, String password);

	public Person get(Integer id);

	/**
	 * 保存Person实例
	 * 
	 * @param person
	 *            需要保存的Person实例
	 * @return 刚刚保存的Person实例的标识属性值
	 */
	public Integer save(Person person);

	/**
	 * 修改Person实例
	 * 
	 * @param person
	 *            需要修改的Person实例
	 */
	public void update(Person person);

	/**
	 * 删除Person实例
	 * 
	 * @param id
	 *            需要删除的Person实例的标识属性值
	 */
	public void delete(Integer id);

	/**
	 * 删除Person实例
	 * 
	 * @param person
	 *            需要删除的Person实例
	 */
	public void delete(Person person);

	/**
	 * 根据用户名查找Person
	 * 
	 * @param name
	 *            查询的人名
	 * @return 指定用户名对应的全部Person
	 */
	public List<person> findByName(String name);

	/**
	 * 查询全部Person实例
	 * 
	 * @return 全部Person实例
	 */
	@SuppressWarnings("unchecked")
	public List findAllPerson();

	/**
	 * 查询数据表中Person实例的总数
	 * 
	 * @return 数据表中Person实例的总数
	 */
	public long getPersonNumber();
}
</person>

PersonDaoImpl.java

package com.wzs.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.wzs.bean.Person;
import com.wzs.dao.PersonDao;

public class PersonDaoImpl implements PersonDao {
	private HibernateTemplate ht = null;
	private SessionFactory sessionFactory;

	// 依赖注入SessionFactory的setter方法
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	// 初始化HibernateTemplate的方法
	private HibernateTemplate getHibernateTemplate() {
		if (ht == null) {
			ht = new HibernateTemplate(sessionFactory);
		}
		return ht;
	}

	/**
	 * 校验用户名密码
	 * 
	 * @param name
	 *            用户名
	 * @param password
	 *            密码
	 * @return true:存在,false:不存在
	 */
	@SuppressWarnings("unchecked")
	public boolean valid(String name, String password) {
		List<person> list = getHibernateTemplate().find("from Person p where p.name=? and p.password=?",
				new String[] { name, password });
		if (list.size() > 0) {
			return true;
		}
		return false;
	}

	/**
	 * 加载Person实例
	 * 
	 * @param id
	 *            需要加载的Person实例的标识属性值
	 * @return 指定id对应的Person实例
	 */
	public Person get(Integer id) {
		return (Person) getHibernateTemplate().get(Person.class, id);
	}

	/**
	 * 保存Person实例
	 * 
	 * @param person
	 *            需要保存的Person实例
	 * @return 刚刚保存的Person实例的标识属性值
	 */
	public Integer save(Person person) {
		return (Integer) getHibernateTemplate().save(person);
	}

	/**
	 * 修改Person实例
	 * 
	 * @param person
	 *            需要修改的Person实例
	 */
	public void update(Person person) {
		getHibernateTemplate().update(person);
	}

	/**
	 * 删除Person实例
	 * 
	 * @param id
	 *            需要删除的Person实例的标识属性值
	 */
	public void delete(Integer id) {
		getHibernateTemplate().delete(get(id));
	}

	/**
	 * 删除Person实例
	 * 
	 * @param person
	 *            需要删除的Person实例
	 */
	public void delete(Person person) {
		getHibernateTemplate().delete(person);
	}

	/**
	 * 根据用户名查找Person
	 * 
	 * @param name
	 *            查询的人名
	 * @return 指定用户名对应的全部Person
	 */
	@SuppressWarnings("unchecked")
	public List<person> findByName(String name) {
		return (List<person>) getHibernateTemplate().find("from Person p where p.name like ?", name);
	}

	/**
	 * 查询全部Person实例
	 * 
	 * @return 全部Person实例
	 */
	@SuppressWarnings("unchecked")
	public List findAllPerson() {
		return (List<person>) getHibernateTemplate().find("from Person");
	}

	/**
	 * 查询数据表中Person实例的总数
	 * 
	 * @return 数据表中Person实例的总数
	 */
	public long getPersonNumber() {
		return (Long) getHibernateTemplate().find("select count(*) from Person as p").get(0);
	}
}
</person></person></person></person>

jsp界面

login.jsp


	
		<title>登录页面</title>
	
	
		

用户登录

用户名:
密  码:

welcome.jsp



	
		<title>成功页面</title>
	
	
		您已经登录!
		<property value="tip"></property>
	



error.jsp


	
		<title>错误页面</title>
	
	
		您不能登录!
	


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are the differences in syntax between MySQL and other SQL dialects?What are the differences in syntax between MySQL and other SQL dialects?Apr 27, 2025 am 12:26 AM

MySQLdiffersfromotherSQLdialectsinsyntaxforLIMIT,auto-increment,stringcomparison,subqueries,andperformanceanalysis.1)MySQLusesLIMIT,whileSQLServerusesTOPandOracleusesROWNUM.2)MySQL'sAUTO_INCREMENTcontrastswithPostgreSQL'sSERIALandOracle'ssequenceandt

What is MySQL partitioning?What is MySQL partitioning?Apr 27, 2025 am 12:23 AM

MySQL partitioning improves performance and simplifies maintenance. 1) Divide large tables into small pieces by specific criteria (such as date ranges), 2) physically divide data into independent files, 3) MySQL can focus on related partitions when querying, 4) Query optimizer can skip unrelated partitions, 5) Choosing the right partition strategy and maintaining it regularly is key.

How do you grant and revoke privileges in MySQL?How do you grant and revoke privileges in MySQL?Apr 27, 2025 am 12:21 AM

How to grant and revoke permissions in MySQL? 1. Use the GRANT statement to grant permissions, such as GRANTALLPRIVILEGESONdatabase_name.TO'username'@'host'; 2. Use the REVOKE statement to revoke permissions, such as REVOKEALLPRIVILEGESONdatabase_name.FROM'username'@'host' to ensure timely communication of permission changes.

Explain the differences between InnoDB and MyISAM storage engines.Explain the differences between InnoDB and MyISAM storage engines.Apr 27, 2025 am 12:20 AM

InnoDB is suitable for applications that require transaction support and high concurrency, while MyISAM is suitable for applications that require more reads and less writes. 1.InnoDB supports transaction and bank-level locks, suitable for e-commerce and banking systems. 2.MyISAM provides fast read and indexing, suitable for blogging and content management systems.

What are the different types of JOINs in MySQL?What are the different types of JOINs in MySQL?Apr 27, 2025 am 12:13 AM

There are four main JOIN types in MySQL: INNERJOIN, LEFTJOIN, RIGHTJOIN and FULLOUTERJOIN. 1.INNERJOIN returns all rows in the two tables that meet the JOIN conditions. 2.LEFTJOIN returns all rows in the left table, even if there are no matching rows in the right table. 3. RIGHTJOIN is contrary to LEFTJOIN and returns all rows in the right table. 4.FULLOUTERJOIN returns all rows in the two tables that meet or do not meet JOIN conditions.

What are the different storage engines available in MySQL?What are the different storage engines available in MySQL?Apr 26, 2025 am 12:27 AM

MySQLoffersvariousstorageengines,eachsuitedfordifferentusecases:1)InnoDBisidealforapplicationsneedingACIDcomplianceandhighconcurrency,supportingtransactionsandforeignkeys.2)MyISAMisbestforread-heavyworkloads,lackingtransactionsupport.3)Memoryengineis

What are some common security vulnerabilities in MySQL?What are some common security vulnerabilities in MySQL?Apr 26, 2025 am 12:27 AM

Common security vulnerabilities in MySQL include SQL injection, weak passwords, improper permission configuration, and unupdated software. 1. SQL injection can be prevented by using preprocessing statements. 2. Weak passwords can be avoided by forcibly using strong password strategies. 3. Improper permission configuration can be resolved through regular review and adjustment of user permissions. 4. Unupdated software can be patched by regularly checking and updating the MySQL version.

How can you identify slow queries in MySQL?How can you identify slow queries in MySQL?Apr 26, 2025 am 12:15 AM

Identifying slow queries in MySQL can be achieved by enabling slow query logs and setting thresholds. 1. Enable slow query logs and set thresholds. 2. View and analyze slow query log files, and use tools such as mysqldumpslow or pt-query-digest for in-depth analysis. 3. Optimizing slow queries can be achieved through index optimization, query rewriting and avoiding the use of SELECT*.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software