Mysql + ssh integration example, with source code download project reference jar download: download. csdn. netdetailadam_zs00002727 project source code: download. csdn. netdetailadam_zs00002749 today took the time to integrate ssh and try again. I hope it will help you! I use mysql data.
Mysql + ssh integration example, with the source code download project reference jar download: http://download.csdn.net/detail/adam_zs/7262727 project source code: http://download.csdn.net/detail/adam_zs/7262749 today took the time to integrate ssh a bit, and then learn again, I hope to help everyone! I use mysql data.
Mysql + ssh integration example, with source code download
Project Reference jar download: http://download.csdn.net/detail/adam_zs/7262727
Project Source: http://download.csdn.net/detail/adam_zs/7262749
Today, I took the time to integrate ssh and try again. I hope it will help you!
I am using a mysql database, and the table creation statement is relatively simple and will not be pasted out. The Set id recorded during table creation is automatically added.
Project file location. The project references the jar package.
Project configuration file
Web. xml
Index. jsp
Org. springframework. web. context. ContextLoaderListener
Struts2
Org. apache. struts2.dispatcher. FilterDispatcher
Struts2
/*
Struts. xml
/Error. jsp
/Welcome. jsp
.
ApplicationContext. xml
Com/wzs/bean/Person. hbm. xml
Org. hibernate. dialect. MySQLInnoDBDialect
Update
True
True
Java code
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
LoginAction. java
Package com. wzs. action; import com. opensymphony. xwork2.ActionSupport; import com. wzs. service. myService; @ SuppressWarnings ("serial") public class LoginAction extends ActionSupport {// The following two attributes used to encapsulate user request parameters: private String name; private String password; // private String tip, an attribute used to encapsulate processing results; // private MyService MS, a business logic component used by the system; // set the setter method required to inject the business logic component public void setMs (MyService MS) {this. ms = ms;}/*** User Login *** @ retu Rn * @ throws Exception */public String login () throws Exception {// call the valid method of the business logic component. // verify that the user name and password entered by the user are correct if (ms. valid (getName (), getPassword () {setTip ("Haha, integration successful! "); 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 {/*** verify username and password ** @ param name * username * @ param password * @ return true: Yes, false: */boolean valid (String name, String password) does not exist );}
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;/*** verify the user name and password ** @ param name * User name * @ param password * @ return true: Yes, 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 {/*** verify username and password ** @ param name * username * @ param password * @ return true: Yes, false: */public boolean valid (String name, String password); public Person get (Integer id ); /*** save the Person instance ** @ param person * The Person instance to be saved * @ return the identity attribute value of the Person instance just saved */public Integer save (Person person Person ); /*** modify the Person instance ** @ param person * The Person instance to be modified */public void update (Person person ); /*** delete Person instance ** @ param id * id attribute value of the Person instance to be deleted */public void delete (Integer id ); /*** delete the Person instance ** @ param person * The Person instance to be deleted */public void delete (Person person ); /***** search for the Person name queried by the user name ** @ param name * @ return specify all persons corresponding to the user name */public List
FindByName (String name);/*** query all Person instances ** @ return all Person instances */@ SuppressWarnings ("unchecked") public List findAllPerson (); /*** query the total number of Person instances in the data table *** @ return the total number of Person instances in the data table */public long getPersonNumber ();}
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; // dependency injection SessionFactory setter method public void setSessionFactory (SessionFactory sessionFactory) {this. sessionFactory = sessionFactory;} // Method for initializing HibernateTemplate private HibernateTemplate getHibernateTemplate () {if (ht = null) {ht = new HibernateTemplate (sessionFactory);} return ht ;} /*** verify username and password ** @ param name * username * @ param password * @ return true: Yes, false: No */@ SuppressWarnings ("unchecked ") public boolean valid (String name, String password) {List
List = getHibernateTemplate (). find ("from Person p where p. name =? And p. password =? ", New String [] {name, password}); if (list. size ()> 0) {return true;} return false ;} /*** load the Person instance ** @ param id * The identity attribute value of the Person instance to be loaded * @ return specifies the Person instance corresponding to the id */public Person get (Integer id) {return (Person) getHibernateTemplate (). get (Person. class, id );} /*** save the Person instance ** @ param person * The Person instance to be saved * @ return the identity attribute value of the Person instance you just saved */public Integer save (Person person Person) {return (Integer) getHibernateTemplate (). save (person);}/*** modify the Person instance ** @ param person * The Person instance to be modified */public void update (Person person) {getHibernateTemplate (). update (person);}/*** delete Person instance ** @ param id * id attribute value of the Person instance to be deleted */public void delete (Integer id) {getHibernateTemplate (). delete (get (id);}/** delete Person instance ** @ param person * The Person instance to be deleted */public void delete (Person person Person) {getHibernateTemplate (). delete (person );} /*** query Person names queried by user name ** @ param name * @ return specify all persons corresponding to the user name */@ SuppressWarnings ("unchecked") public List
FindByName (String name) {return (List
) GetHibernateTemplate (). find ("from Person p where p. name like? ", Name);}/*** query all Person instances ** @ return all Person instances */@ SuppressWarnings (" unchecked ") public List findAllPerson () {return (List
) GetHibernateTemplate (). find ("from Person");}/*** query the total number of Person instances in the data table ** @ return total number of Person instances in the data table */public long getPersonNumber () {return (Long) getHibernateTemplate (). find ("select count (*) from Person as p "). get (0 );}}
Jsp Interface
Login. jsp
<% @ Page language = "java" contentType = "text/html; charset = UTF-8" %>Logon page
Welcome. jsp
<% @ Page language = "java" contentType = "text/html; charset = UTF-8 "%> <% @ taglib prefix =" s "uri ="/struts-tags "%>Success pageYou have logged on!
Error. jsp
<% @ Page language = "java" contentType = "text/html; charset = UTF-8" %>Error PageYou cannot log on!