eclipse環境搭建ssh(Struts2+Spring2.5+Hibernate3)框架小談(下)
不過,我一定會用心的編輯每一篇文章,一方面便於自己回顧,另一方便也希望能夠幫到需要的小夥伴。
※1、ssh框架如何實現一個功能,(思考:頁面上提交的資料到底怎麼去的資料庫 然後又回到頁面重新顯示的呢,我到底應該做些什麼來實現它)
(以下使用“註冊”功能來詳細講解)
View (檢視):本專案中JSP來充當這個角色
1)、reg.jsp 註冊過程資料流詳細解析 原始碼如下
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>使用者註冊介面</title>
</head>
<body>
<form action=" reg" method="post" name="regForm">
<table>
<tr>
<td>使用者名稱</td>
<td><input type="text" name="userName" size="15" /></td>
</tr>
<tr>
<td>密碼</td>
<td><input type="password" name="pwd" size="15" /></td>
</tr>
<tr>
<td>姓名</td>
<td><input type="text" name="name" size="15" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="註冊"></td>
</tr>
</table>
</form>
</body>
</html>
reg.jsp中
<form action="reg" method="post" name="regForm">----->reg是怎麼知道自己需要幹什麼事情的呢?
此刻至關重要的一個檔案就是struts.xml(第一個配置檔案)
jsp提交之後會尋找對應的action來操作,這個Action呢?????就定義在struts.xml中,action的定義規範 一般為如下形式
<action name="login" class="LoginAction">
<result name="success">/result.jsp</result>
<result name="input">/login.jsp</result>
</action>
附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>
<constant name="struts.i18n.encoding" value="GBK"></constant>
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
<constant name="struts.objectFactory" value="spring"/>
<package name="ssh" namespace ="/" extends="struts-default">
<!-- 此處的class的內容要與Spring配置檔案中的bean的id相同 -->
<action name="login" class="LoginAction">
<result name="success">/result.jsp</result>
<result name="input">/login.jsp</result>
</action>
<action name="reg" class="RegAction">
<result name="success">/regsuccess.jsp</result>
<result name="input">/reg.jsp</result>
</action>
<action name="listUser" class="ListUserAction">
<result name="success">/listUsers.jsp</result>
</action>
<action name="deleteUser" class="DeleteUserAction">
<result name="success" type="redirect">listUser.action</result>
</action>
<action name="updateUserP" class="UpdateUserPAction">
<result name="success" >/update.jsp</result>
</action>
<action name="updateUser" class="UpdateUserAction">
<result name="success" type="redirect">listUser.action</result>
</action>
<!-- <action name="reg" class="com.jh.action.UserAction" >
<result name="success">/regsuccess.jsp</result>
</action> -->
</package>
</struts>
接下就是ACTION會分配業務給這個請求,此時需要關聯的就是spring的配置檔案applicationContext.xml(第二個配置檔案)applicationContext.xml的檔案中會有一個與上述struts.xml中呼應的bean
※也就是struts.xml的class的內容要與Spring配置檔案 applicationContext.xml中的bean的id相同
<bean id="RegAction" class="com.jh.action.RegAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
附 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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 配置資料來源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- 指定連線資料庫的驅動 -->
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<!-- 指定連線資料庫的URL -->
<property name="url" value="jdbc:mysql://localhost:3306/Kind" />
<!-- 指定連線資料庫的使用者名稱 -->
<property name="username" value="root" />
<!-- 指定連線資料庫的密碼 -->
<property name="password" value="123456" />
</bean>
<!-- 配置SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.connection.autocommit">true </prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="sql_format">true</prop>
</props>
</property>
<property name="mappingResources">
<!-- 指定hibernate對映檔案 -->
<list>
<value>com/jh/entity/User.hbm.xml</value>
</list>
</property>
</bean>
<!-- Dao配置 -->
<bean id="userDao" class="com.jh.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- Service配置 -->
<bean id="userService" class="com.jh.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="RegAction" class="com.jh.action.RegAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
<bean id="LoginAction" class="com.jh.action.LoginAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
<bean id="ListUserAction" class="com.jh.action.ListUserAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
<bean id="DeleteUserAction" class="com.jh.action.DeleteUserAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
<bean id="UpdateUserPAction" class="com.jh.action.UpdateUserPAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
<bean id="UpdateUserAction" class="com.jh.action.UpdateUserAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
<!-- <bean id="regAction" class="com.jh.action.UserAction" scope="prototype" >
<property name="userService" ref="userService"></property>
</bean> -->
</beans>
總結一下applicationContext.xml:個人認為這個檔案就是連線了專案中定義的Action和Service起到了粘合的作用!
知道了Action是什麼之後我們需要了解的就是Service是什麼?
Service就是業務層,業務層是“三層框架(三層體系結構)”的其中一層
簡要解釋一下三層框架(這個Kind專案擴充套件了幾個功能所以和之前的有些不一樣 但是框架沒有變化)
2、其他配置檔案以及jsp原始碼
配置檔案部分
1)、User.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Mapping file autogenerated by MyEclipse Persistence Tools -->
<hibernate-mapping>
<class name="com.jh.entity.User" table="USERDETAILS">
<id name="id">
<column name="ID" />
<generator class="increment" />
</id>
<property name="userName" type="java.lang.String">
<column name="userName" />
</property>
<property name="pwd" type="java.lang.String">
<column name="pwd" />
</property>
<property name="name" type="java.lang.String">
<column name="name" />
</property>
</class>
</hibernate-mapping>
2)、mess.properties
loginPage=登入頁面
errorPage=錯誤頁面
succPage=成功頁面
failTip=對不起,您不能登入!
succTip=歡迎,{0},您已經登入!
user=使用者名稱
pass=密碼
login=登入
3)、web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>TestDemo</display-name>
<!-- 用來定位Spring框架配置檔案 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext*.xml,classpath*:applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list><welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- 配置Struts -->
<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>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
jsp部分
1)、regsuccess.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>註冊成功e</title>
</head>
<body>
<h1>註冊成功</h1><s:a href="login.jsp">登入</s:a><br/>
</body>
</html>
2)、login.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>使用者登陸介面</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="login">
<label>姓名:
<input type="text" name="userName" />
</label>
<p>
<label>
密碼:
<input type="text" name="password" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</p>
</form>
</body>
</html>
3)、result.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登陸成功</title>
</head>
<body>
成功
</body>
</html>
4)、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>My JSP 'index.jsp' starting page</title>
</head>
<body>
<h1><font color="red">Operation List</font></h1>
<s:a href="reg.jsp">註冊</s:a><br/>
<s:a href="login.jsp">登入</s:a><br/>
<s:a href="listUser.action">List Users</s:a>
</body>
</html>
3、執行截圖(+後期擴充套件功能截圖)
1)、首頁
2)、註冊
3)、註冊成功
4)、登入
5)、登入成功
6)、顯示所有使用者
7)、刪除使用者
8)、更新使用者資訊
9)、刪除、更新之後
極少數情況下搭建過程可能也會遇到與以下一個檔案有關的問題
\workspace\Kind\.settings\org.eclipse.wst.common.project.facet.core.xml (本工程對應內容如下)
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Apache Tomcat v8.0"/>
<fixed facet="jst.web"/>
<fixed facet="wst.jsdt.web"/>
<fixed facet="java"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.web" version="3.1"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
相關jar包和工程下載連結如下
以上為全部搭建過程,內容如有不當或者錯誤之處,希望閣下可以聯絡我,小生必加以糾正,讓我們一起學習郵箱------330151437(新增好友請備註csdn+博文名稱)!
相關推薦
eclipse環境搭建ssh(Struts2+Spring2.5+Hibernate3)框架小談(下)
不過,我一定會用心的編輯每一篇文章,一方面便於自己回顧,另一方便也希望能夠幫到需要的小夥伴。 ※1、ssh框架如何實現一個功能,(思考:頁面上提交的資料到底怎麼去的資料庫 然後又回到頁面重新顯示的呢,我到底應該做些什麼來實現它) (以下使用“註冊”功能來詳細講解) V
Smobiler資料準備與環境搭建——C# 或.NET Smobiler例項開發手機app(一)
目錄 一、 前言 二、 關於"選擇" 三、 資料準備 1、 Smobiler介紹 2、 三款開源軟體原始碼下載 3、 控制元件使用例項 四、 環境搭建到實現HelloWorld 1、 安裝VS2015及以上 2、 安裝Designer 3、 實現Hello
【Flutter 系列——1】Flutter環境搭建及配置這一篇就夠了(Windows)
最近正式入坑Flutter,首先從環境搭建開始,看了網上好多關於Windows環境搭建的資料,基本都是按官方文件寫的,看完的感受是,還不如直接去看官方文件。 本文主要總結我實際搭建的過程,最後發現不一定按網上那些部落格或者官方文件寫的來也可以搭建成功。 總的來說需要的
5.什麽是tensor(下)
bubuko 技術分享 port flow highlight 什麽是 div imp light import tensorflow as tf # tensorflow還支持變量的定義 var = tf.Variable(3) print(var) # <t
ssh框架搭建Struts2.06+spring2.5+hibernate3.2整合例項程式碼教程步驟
最近閒來無事可做,於是開始學習struts2。Struts2和struts1、webwork2有什麼區別我也不說了,網上有很多這方面的資料。以前在專案中從未使用過struts,一直使用spring+hibernate,現在既然學習了Struts,也不能浪費,於是乎開始琢
eclipse(luna)搭建SSH(struts2+spring4+hibernate4)
eclipse enc cti ppi 文件中 releases path ram cat 準備工作: java環境 tomcat環境(這裏使用tomcat8.0) eclipse(已添加了server runtime插件) ========================
SSM+Maven+eclipse環境搭建
pen test 異步 pan con spec xid iba action 1、創建maven項目 版本:Java 1.8 Mysql 6.0 1)New Maven project 頁面 勾選 Create a simple project (不使
Kotlin Eclipse 環境搭建
操作 market 結果 -o board 官方 jetbrains 打開 html Kotlin是JetBrains開發的基於JVM的語言。JetBrains是一家捷克的軟件開發公司,該公司位於捷克的布拉格,研發了IntelliJ IDEA這款相對於Eclipse有較大改
Java學習不走彎路教程(7.Eclipse環境搭建)
運行環境 圖片 bin 分享 ron 成功 完成後 所有 點擊 7.Eclipse環境搭建 在前幾章,我們熟悉了DOS環境下編譯和運行Java程序,對於大規模的程序編寫,開發工具是必不可少的。Java的開發工具比較常用的是Eclipse。在接下來的教程中,我們將基於Ecli
Java學習不走彎路教程(2.Eclipse環境搭建)
目錄 con pac 結果 automatic eclips pat mat 行程 Eclipse環境搭建 在前一章,我們熟悉了DOS環境下編譯和運行Java程序,對於大規模的程序編寫,開發工具是必不可少的。Java的開發工具比較常用的是Eclipse。在接下來的教程中,我
Eclipse環境搭建並且執行wordcount程式
一、安裝Hadoop外掛 1. 所需環境 hadoop2.0偽分散式環境平臺正常執行 所需壓縮包:eclipse-jee-luna-SR2-linux-gtk-x86_64.tar.gz 在Linux環境下執行的eclipse軟體壓縮包,
pydev+python+Eclipse環境搭建+ 除錯快捷鍵彙總
編輯器: Eclipse + pydev外掛 1. Eclipse是寫JAVA的IDE, 這樣就可以通用了,學習代價小。 學會了Eclipse, 以後寫Python或者JAVA 都可以。 2. Eclipse, 功能強大。 3. Eclipse跨平臺, 可以在Mac上
eclipse環境搭建2種方法
方法一: 直接在安卓中文站下載整合好得ADT Bundle(包含了Eclipse、ADT外掛和SDK Tools,是已經整合好的IDE)只需安裝好Jdk即可開始開發。如果不想配置各種環境得可以參考此方法 方法二: jdk+eclipse+adt 安裝JDK
hadoop環境搭建之 linux CENTOS6.5 最小化安裝步驟
安裝VmwareWorkStation下載CentOS6.5 iso 映象檔案點選建立新的虛擬機器,選擇典型,點下一步選擇稍後安裝作業系統選擇Linux CentOS64為選擇安裝路徑和虛擬機器名稱分配50G磁碟空間, 選擇將虛擬磁碟拆分多個檔案選擇自定義硬體安裝過程先分配4
eclipse環境搭建之五:Scala
最近由於開發的要求,需要使用Scala語言,這裡就在前面搭建的eclipse的基礎上搭建一個Scala的開發環境。 1、首先,你需要去Scala的官網上載你需要的安裝包,這裡我下載了最新的2.11.8的msi包。 2、雙擊進行安裝: 點選"Next" 選擇"I acc
學習筆記1:深度學習環境搭建win+python+tensorflow1.5+CUDA9.0+cuDNN7.0
2018年2月13買了一臺Dell Inspiron7577,i7-7700hq、1050Ti顯示卡、win10家庭版。由於課題需要開始學習深度學習,之前在實驗室和自己的筆記本上安裝TensorFlow總是不成功,不然就是僅實現cpu運算。本次安裝主要是按照這
1:自動化測試環境--Eclipse環境搭建
一:Eclipse安裝(for mac) ①:Eclipse 的官方下載地址: ②:Eclipse 環境下Maven 外掛的安裝. 開啟整合開發工具Eclipse,點選Help->Install New Software 進入到如下的介面: Name:自己隨便
Ubuntu16.04 jdk+Eclipse環境搭建, jdk版本自由切換
1 下載解壓JDK 2 設定JAVA_HOME等環境變數 用文字編輯器開啟系統配置檔案 geidt ~/.bashrc 在檔案最後新增以下幾行 export JAVA_HOME=/home/sxcai188/0_3rdparties
hadoop2.7.2 win7 eclipse環境搭建測試
環境搭建參照上一篇hadoop2.7.2 win7基礎環境搭建。 Eclipse hadoop外掛下載2.7.2:http://download.csdn.net/detail/fly_leopard/9503172 將下載的檔案解壓,將jar包放到Eclipse/plug
CentOS 6.5搭建Smokeping平臺(下)
smokeping1、添加監控點[[email protected]/* */ ~]# vi /usr/local/smokeping/etc/config ##添加以下內容## + Other menu = 三大網絡監控 title = 監控統計 ++ dianxin menu = 電信網絡監