inotgo.com

Download area
File name File size
lib.rar 16m
ssh.rar 16m

Tool version compatibility problem
This example demonstrates from 0 Start integrating one by one SSH Steps for , To learn this knowledge , Need to have Spring, Struts, Hibernate Basis of , Without these foundations , Please master the basics before you learn , Don't jump to learn , The last pit is yourself

This example demonstrates from struts,spring,hibernate Step by step configuration , The complete runnable instance can be downloaded on the right

Must read : Framework based programs run successfully , For JAR Package version , The correctness of the configuration file has strict requirements , Anything goes wrong , Will cause the framework program to fail . If you are learning this framework for the first time , Be sure to follow the instructions of the tutorial strictly , Completely imitate the operation , Until you successfully see the running effect . After the first success , Confidence , Ideas will have a better cushion , Then according to their doubts , stay “ success ” Make the desired changes and adjustments to your code , This can greatly save learning time , increase of efficiency , Don't change it at once , Create obstacles to your learning
Correct

Step 1 : Create database   
Step 2 : Create table   
Step 3 : Prepare data   
Step 4 : Run... First , Learn again   
Step 5 : New project   
Step 6 : Import jar   
Step 7 : pojo   
Step 8 : hbm   
Step 9 : DAO   
Step 10 : Service   
Step 11 : ProductAction   
Step 12 : struts.xml   
Step 13 : applicationContext.xml   
Step 14 : to configure web.xml   
Step 15 : list.jsp   
Step 16 : visit http://127.0.0.1/listProduct   
Step 17 : Runnable project   
Step 18 : Train of thought diagram   
Step 19 : practice   

First prepare the database how2java
If the database is not installed , Please refer to Install mysql-server

notes : The newly installed database account password is root:admin, In the subsequent configuration , I also use this account password . If the password is not this , The runnable items in the upper right corner of this knowledge point can't run , So try to change the password to admin, Password modification method : modify root password
Prepare the table product_, have 3 Fields , namely
Primary key id( Self growth )
String format name
Floating point format price
use how2java; CREATE TABLE product_ ( id int(11) NOT NULL AUTO_INCREMENT, name varchar(30) , price float , PRIMARY KEY (id) ) DEFAULT CHARSET=UTF8;
use how2java;
 
CREATE TABLE product_ (
  id int(11) NOT NULL AUTO_INCREMENT,
  name varchar(30) ,
  price float ,
  PRIMARY KEY (id)
) DEFAULT CHARSET=UTF8;
use how2java; delete from product_; INSERT INTO product_ VALUES (null,' Products a',88.88); INSERT INTO product_ VALUES (null,' Products b',88.88); INSERT INTO product_ VALUES (null,' Products c',88.88); INSERT INTO product_ VALUES (null,' Products x',88.88); INSERT INTO product_ VALUES (null,' Products y',88.88); INSERT INTO product_ VALUES (null,' Products z',88.88);
use how2java;
delete from product_;
INSERT INTO product_ VALUES (null,' Products a',88.88);
INSERT INTO product_ VALUES (null,' Products b',88.88);
INSERT INTO product_ VALUES (null,' Products c',88.88);
INSERT INTO product_ VALUES (null,' Products x',88.88);
INSERT INTO product_ VALUES (null,' Products y',88.88);
INSERT INTO product_ VALUES (null,' Products z',88.88);
SSH Integration requires many steps , Any step is missing , Did something wrong , Can fail , This will affect the confidence of learning , And mistakenly think that this tutorial is impassable .

So first download the runnable project in the upper right corner ssh.rar, Unzip and import to eclipse In , Start Tomcat, Observe for normal operation . Make sure you can run , Make sure the tutorial can run , Learn the following .

Import to Eclipse For the method of and operation in, please refer to : Import dynamic Web Project to Eclipse In

After successful deployment , Test address , You should see the effect shown in the figure

http://127.0.0.1:8080/ssh/listProduct
 Run... First , Learn again
stay eclipse New item in ssh, use dynamic web project The way . Students who are not familiar with this way , Please refer to use Dynamic Web Project Develop in a way J2EE application
 New project
Download the... In the upper right corner lib.rar, Unzip and copy to e:/project/ssh/WebContent/WEB-INF/lib Under the directory
package com.how2java.pojo; public class Product { private int id; private String name; private float price; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } }
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.how2java.pojo"> <class name="Product" table="product_"> <id name="id" column="id"> <generator class="native"> </generator> </id> <property name="name" /> <property name="price" /> </class> </hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.how2java.pojo">
	<class name="Product" table="product_">
		<id name="id" column="id">
			<generator class="native">
			</generator>
		</id>
		<property name="name" />
		<property name="price" />
	</class>
	
</hibernate-mapping>
DAO Part by interface ProductDAO And its implementation class ProductDAOImpl constitute
ProductDAO The interface declares a method list()、add(Product p).
ProductDAOImpl Class inherits Hibernatetemplete, And implement the interface ProductDAO.
package com.how2java.dao; import java.util.List; import com.how2java.pojo.Product; public interface ProductDAO { public List<Product> list(); public void add(Product p); }
package com.how2java.dao.impl; import java.util.List; import org.springframework.orm.hibernate3.HibernateTemplate; import com.how2java.dao.ProductDAO; import com.how2java.pojo.Product; public class ProductDAOImpl extends HibernateTemplate implements ProductDAO{ public List<Product> list() { return find("from Product"); } @Override public void add(Product p) { save(p); } }
Service Part by interface ProductService And its implementation class ProductServiceImpl constitute
ProductService The interface declares a method list().
ProductServiceImpl Implementation interface ProductService, And accept productDAO Injection of .
list Method is business method ,productDAO Find all data , If it is empty , Just insert it into the database 5 Data bar .
package com.how2java.service; import java.util.List; import com.how2java.pojo.Product; public interface ProductService { public List<Product> list(); }
package com.how2java.service.impl; import java.util.List; import org.springframework.orm.hibernate3.HibernateTemplate; import com.how2java.dao.ProductDAO; import com.how2java.pojo.Product; import com.how2java.service.ProductService; public class ProductServiceImpl implements ProductService { ProductDAO productDAO; public List<Product> list() { List<Product> products= productDAO.list(); if(products.isEmpty()){ for (int i = 0; i < 5; i++) { Product p = new Product(); p.setName("product " + i); productDAO.add(p); products.add(p); } } return products; } public ProductDAO getProductDAO() { return productDAO; } public void setProductDAO(ProductDAO productDAO) { this.productDAO = productDAO; } }
ProductAction Provide for ProductService Injection of , With the help of SSH Integration of ,ProductAction It acts as a very simple control layer :
1. Get data
2. Jump to page “listJsp”
package com.how2java.action; import java.util.List; import com.how2java.pojo.Product; import com.how2java.service.ProductService; public class ProductAction { ProductService productService; List<Product> products; public String list() { products = productService.list(); return "listJsp"; } public ProductService getProductService() { return productService; } public void setProductService(ProductService productService) { this.productService = productService; } public List<Product> getProducts() { return products; } public void setProducts(List<Product> products) { this.products = products; } }
appoint objectFactory by spring, hold action Life cycle management for spring conduct
<?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> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <constant name="struts.objectFactory" value="spring"/> <package name="basicstruts" extends="struts-default"> <action name="listProduct" class="productActionBean" method="list"> <result name="listJsp">list.jsp</result> </action> </package> </struts>
<?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>
  <constant name="struts.i18n.encoding" value="UTF-8"></constant>
  
  <constant name="struts.objectFactory" value="spring"/>
  
  <package name="basicstruts" extends="struts-default">
  
  <action name="listProduct" class="productActionBean" method="list">
    <result name="listJsp">list.jsp</result>
  </action>
  
</package>
</struts>
applicationContext.xml It should be WEB-INF Under the directory
Provide action Management of , And create action When I was , injection dao
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean name="productActionBean" class="com.how2java.action.ProductAction"> <property name="productService" ref="productServiceImpl" /> </bean> <bean name="productServiceImpl" class="com.how2java.service.impl.ProductServiceImpl"> <property name="productDAO" ref="productDAOImpl" /> </bean> <bean name="productDAOImpl" class="com.how2java.dao.impl.ProductDAOImpl"> <property name="sessionFactory" ref="sf" /> </bean> <bean name="sf" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="ds" /> <property name="mappingResources"> <list> <value>com/how2java/pojo/Product.hbm.xml</value> </list> </property> <property name="schemaUpdate"> <value>true</value> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=true hbm2ddl.auto=update </value> </property> </bean> <bean name="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/how2java?characterEncoding=UTF-8" /> <property name="username" value="root" /> <property name="password" value="admin" /> </bean> </beans>
web.xml Add Context monitor
<web-app> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
<web-app>
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
			org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
		</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>struts2</filter-name>
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>REQUEST</dispatcher>		
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<listener>
  		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 	</listener>
 	
</web-app>
For display products of jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%> <%@ taglib prefix="s" uri="/struts-tags" %> <%@page isELIgnored="false"%> <table> <tr> <td>id</td> <td>name</td> </tr> <s:iterator value="products" var="p"> <tr> <td>${p.id}</td> <td>${p.name}</td> </tr> </s:iterator> </table>
Step 16 :

visit http://127.0.0.1/listProduct

edit top fracture
Deployed in Tomcat In , Restart tomcat, Then visit the address , Observation effect

http://127.0.0.1:8080/ssh/listProduct


For deployment methods, please refer to Through Eclipse Start Tomcat-Run On Server
 visit http://127.0.0.1/listProduct
In the upper right corner, there is the runnable Project Download corresponding to this knowledge point , I really can't do it myself , Just download and unzip it and compare it
1. Access path /listProduct
2. web.xml The filter in will submit the request to struts Process
3. struts According to listProduct Create corresponding productActionBean
At this point productActionBean No longer by Struts Create yourself , But by Spring establish
4. spring According to applicationContext.xml establish productActionBean Corresponding object ProductAction
5. Spring establish ProductAction When I was injection Service
6. establish Service Inject when needed DAO
7. Struts Call ProductAction of list method
8. stay list Method invocation is good. dao, Access the database , Query results
9. Jump to list.jsp Display data
 Train of thought diagram
Step 19 :

practice

edit top fracture   Wrong posture , get half the results with double the effort ! Click to see the correct posture for the exercise
Based on this example , use SSH Make a set of products increase Delete change check


The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .


Q & A area    
2021-03-20 stationmaster ,SSH Is there no version of tmall ?
How do you do 007

stationmaster ,SSH Is there no version of tmall ?




2 One answer

How do you do 007
Answer time :2021-04-02
Thank you very much.

Hard training technique
Answer time :2021-03-29
The link is hidden , ad locum . /k/tmall-ssh/tmall-ssh-1159/1159.html



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see




2020-07-23 Why only one of the two rewrite methods has override
Wake up from the dead

stay ProductDaoImpl In this class , Both methods should be overridden . But only add() The method is added with a override







The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see




2020-02-24 struts.xml Ask questions
2019-12-02 Why is the interface used here . method ? It should not be a class that implements this interface . Method ?
2019-10-04 404 Error report not found , This example doesn't work


Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 48 Previous questions , please Click to view

Please... Before asking questions land
The question has been submitted successfully , Auditing . Please My question Check the question record at , thank you
about JAVA Frame -SSH- Integration steps Your questions

Try to provide Screenshot code and Abnormal information , Help to analyze and solve problems . You can also enter this station QQ Group communication : 496725845
Ask questions and try to provide complete code , Environment description , The more conducive to the recurrence of the problem , The faster your question can be answered .
Have questions about the code in the tutorial , Please provide which step , Which line is in doubt , This makes it easy to quickly locate the problem , Improve the speed at which questions are answered
In the thousands of questions that already exist , A considerable proportion , Because of the use of and webmaster Different versions of the development environment Resulting in , For example jdk, eclpise, idea, mysql,tomcat Wait, the version of the software is inconsistent .
Please use the same version as the webmaster , You can save yourself a lot of learning time . The webmaster sorted out the software versions used in teaching , It's all here , Convenient for everyone to download : /k/helloworld/helloworld-version/1718.html

Upload screenshot