Struts和Spring项目

Struts和Spring项目

标签: JAVA框架


第一步配置环境

1. 首先配置struts环境

1> 在src目录下创建一个struts.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
</struts>
2> 在WEB-INF目录下创建一个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">
    <!--核心拦截器 -->
    <!--Filter名字-->
  <filter-name>struts2</filter-name>
  <!--Filter实现类-->
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <!-- 选择拦截的url -->
  <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>
3>导入jar包

2. 加入spring环境

1> 在web.xml文件中加入spring核心容器
<!-- web中集成spring核心容器 -->
  <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
2> 在WEB-INF下创建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"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" 
>

<bean name="LoginAction" class="com.action.LoginAction" scope="singleton">
<!-- 装配 -->
<property name="bus" ref="BusinessService"></property>
</bean>
<bean name="BusinessService" class="com.service.impl.BusinessServiceImpl" scope="prototype">
<!-- 装配 -->
<property name="dao" ref="SomeDao"></property>
</bean>
<bean name="SomeDao" class="com.dao.impl.SomeDaoImpl"></bean>
</beans>
3>Struts.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
<package name="p1" extends="struts-default">
<action name="login" class="LoginAction" method="login"><!--class的名字需要跟applicationContext.xml文件中的LoginAction名字一致-->
<result name="success">/login/home.jsp</result>
<result name="error">/login/login.jsp</result>
</action>
</package>
</struts>

3.接入美工页面 查看需求

4.第一步

1>查看index.jsp
2>进入login/login.jsp
更换struts标签 
第一步引入struts标签<%@taglib prefix="s" uri="/struts-tags" %>

改标签



加入action 配置struts.xml 配置application

写bean user

action实现modeldriven


写业务逻辑层

写interface UserService 写 userLogin方法 实现类
写interface UserDao 写userLogin方法 实现类
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值