ssh框架搭建
!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd" struts !-- 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 -- constant name="struts.i18n.encoding" value="UTF-8" / !-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -- constant name="struts.serve.static.browserCache" value="false" / !-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -- constant name="struts.configuration.xml.reload" value="true" / !-- 开发模式下使用,这样可以打印出更详细的错误信息 -- constant name="struts.devMode" value="true" / include file="admin.xml" / /struts
!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd" struts package name="admin" extends="struts-default" action name="admin_*" method="{1}" result name="login" /backend/main.jsp !-- 页面跳转 -- /result result name="delSuc" type="redirectAction" param name="actionName" admin_login /param !-- action跳转 -- /result /action /package /struts
!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" !-- Generated by MyEclipse Hibernate Tools. -- hibernate-configuration session-factory mapping resource="com/d3/d3studio/model/Admin.hbm.xml" / /session-factory /hibernate-configuration
?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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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 " bean id="dataSource" !-- 指定连接数据库的JDBC驱动 -- property name="driverClass" value com.mysql.jdbc.Driver /value /property !-- 连接数据库所用的URL -- property name="jdbcUrl" value jdbc:mysql://localhost:3306/pacs /value /property !-- 连接数据库的用户名 -- property name="user" value root /value /property !-- 连接数据库的密码 -- property name="password" value root /value /property !-- 设置数据库连接池的最大连接数 -- property name="maxPoolSize" value 20 /value /property !-- 设置数据库连接池的最小连接数 -- property name="minPoolSize" value 2 /value /property !-- 设置数据库连接池的初始化连接数 -- property name="initialPoolSize" value 2 /value /property !-- 设置数据库连接池的连接的最大空闲时间,单位为秒 -- property name="maxIdleTime" value 20 /value /property /bean bean id="sessionFactory" property name="dataSource" ref bean="dataSource" / /property property name="hibernateProperties" props prop key="hibernate.dialect" org.hibernate.dialect.MySQLDialect /prop prop key="hibernate.show_sql" true /prop prop key="hibernate.fromat_sql" true /prop prop key="hibernate.generate_statistics" true /prop prop key="hibernate.connection.release_mode" auto /prop prop key="hibernate.autoReconnect" true /prop prop key="hibernate.cache.use_query_cache" true /prop prop key="cache.use_second_level_cache" true /prop prop key="hibernate.cache.provider_class" org.hibernate.cache.EhCacheProvider /prop /props /property property name="mappingResources" list value com/d3/pacs/model/Admin.hbm.xml /value -- 对应model包里的映射 -- /list /property /bean bean id="txManager" property name="dataSource" ref="dataSource" / /bean tx:annotation-driven transaction-manager="txManager" / -- 使用spring的注入 -- bean id="adminDAO" property name="sessionFactory" ref="sessionFactory" / /bean bean id="adminService" property name="adminDAO" ref="adminDAO" / /bean bean id="adminAction" scope="prototype" property name="adminService" ref="adminService" / /bean /beans
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_3_0.xsd" display-name /display-name !-- 配置struct2-- 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 !-- 启动Spring容器 -- listener listener-class org.springframework.web.context.ContextLoaderListener /listener-class /listener !-- 默认启动项 -- welcome-file-list welcome-file login.jsp /welcome-file /welcome-file-list /web-app
public class AdminAction extends ActionSupport { private static Logger logger = Logger.getLogger(AdminAction.class); private AdminService adminService; private Admin admin; public AdminService getAdminService() { return adminService; } public void setAdminService(AdminService adminService) { this.adminService = adminService; } public Admin getAdmin() { return admin; } public void setAdmin(Admin admin) { this.admin = admin; } // 管理员登陆 public String login() { if(adminService.login(admin) !=null){ HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(true); session.setAttribute("admin1", admin); return "login"; } else return "loginFail"; } // 管理员注册 public String regist() { return "regist"; } // 退出管理员 public String exit() { HttpServletRequest request = ServletActionContext.getRequest(); request.getSession().removeAttribute("admin1"); return "exit"; }
七、 访问流程: 在jsp中提交action 提交表单 form id="login" action="/my/admin_login" method="post"
/my是我的tomcat自己定义的虚拟目录, admin_* 对应的是admin.xml中 action name="admin_*" method="{1}"
访问admin_login 对应的就是action类中的public String login()的方法 ,根据此方法返回的String
对应的也是admin.xml 中 ,返回login则会跳刀main.jsp
result name="login"
/backend/main.jsp !-- 页面跳转 --
/result
result name="regist"
/backend/main.jsp !-- 页面跳转 --
/result
result name="delSuc" type="redirectAction"
param name="actionName" admin_login /param !-- action跳转 --
/result
另外,struts会自动匹配类属性和jsp中name
比如:
jsp里面有 : INPUT "name"
对应在action里面,如果有name的属性,只要提供get,set方法,那么jsp中的name就会传到action
另外还可以: INPUT "admin.name"
对应action里面有个admin的类属性且 admin有name属性, 则会赋值
下载地址: SSH框架模板,已搭建完毕 点击下载
相关文章
- AutoDL算力租用++Pycharm中SSH、SFTP连接远程服务器[通俗易懂]
- linux配置ssh-key
- 虚拟机usb设备连接不成功_ssh怎么连接虚拟机
- go语言 ssh_websshpro
- SSH PuTTY 登录暴力破解器
- 通过 SSH 在远程 Linux 系统上运行命令的方法
- 为什么我们要使用ssh框架技术,及感想详解编程语言
- 登录开启Linux安全之门:启用SSH登录(linux允许ssh)
- 远程连接探索Linux如何建立SSH远程连接(linux建立ssh)
- Maven搭建SSH(Struts2+Spring+Hibernate)框架入门教程(附带实例)
- 让我们用SSH登录Linux吧!(使用ssh登录linux)
- Linux SSH连接失败的谜题(linuxssh连不上)
- 服务Linux查看SSH服务:实战指南(linux怎么查看ssh)
- 搭建Linux外网SSH访问环境(linux外网访问ssh)
- 使用SSH操作Linux服务器:必备技能(ssh操作linux)
- Linux SSH: 无线网络安全的重要保障(linux的ssh是什么)
- 同步使用Linux实现SSH时间同步(linuxssh时间)
- Linux白名单构建SSH安全防护(linux白名单ssh)
- 在 AWS 中使用 Ansible 来管理你的 SSH 密钥
- 快速入门:Linux系统SSH连接操作指南(linux系统ssh)
- Linux启用SSH远程访问实现安全连接(linux启动ssh)
- 无痛远程控制大法:Linux SSH 访问,让工作更高效!(linuxssh访问)
- 学习C,把SSH和MySQL整合在一起(c# ssh mysql)
- SSH远程配置Redis实现服务器性能优化(ssh 配置 redis)
- 挖掘更多可能启用SSH框架Redis(ssh框架使用redis)
- 使用SSH远程查看Redis状态(ssh查看redis)
- SSH实现Redis集群整合赋予资源集群新的生命力(ssh整合redis集群)