maven配置文件

	<!-- servlet -->
  	<dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>javax.servlet-api</artifactId>
		<version>3.0.1</version>
	</dependency>

	<!-- Spring-context -->
	<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.2.2.RELEASE</version>
    </dependency>
    <!-- spring web -->
    <dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-web</artifactId>
		<version>4.2.2.RELEASE</version>
	</dependency>

	<!-- struts -->
	<dependency>
    	<groupId>org.apache.struts</groupId>
    	<artifactId>struts2-core</artifactId>
    	<version>2.3.24.1</version>
	</dependency>

	<!-- struts-spring-plugin -->
	<dependency>
	<groupId>org.apache.struts</groupId>
	<artifactId>struts2-spring-plugin</artifactId>
	<version>2.3.24.1</version>
	</dependency>

spring配置文件

<?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-3.0.xsd"
    default-autowire="byType">

	<bean id="mydata" class="webapp.Data">
		<property name="name" value="tian"></property>
		<property name="age" value="23"></property>
	</bean>
</beans>

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>
     <package name="default" namespace="/" extends="struts-default">
        <action name="login" class="mydata" method="execute">
            <result name="success">index1.jsp</result>
        </action>
     </package>
</struts>

web.xml配置文件

  <!-- 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>

  <!-- spring配置 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- spring 配置文件 -->
  <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>WEB-INF/classes/applicationContext.xml</param-value>
  </context-param>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

Data.Class

public class Data {

	String name;
	int age;
	public void setName(String name)
	{
		System.out.println(name);
		this.name=name;
	}
	public String getName()
	{
		return name;
	}
	public void setAge(int age)
	{
		System.out.println(age+"------------------------------------");
		this.age=age;
	}
	public int  getAge()
	{
		return age;
	}
	public String execute()
	{
		ActionContext.getContext().getApplication().put("name",name);
		ActionContext.getContext().getApplication().put("age", age);
		ActionContext.getContext().getSession().put("name",name);
		ActionContext.getContext().getSession().put("age", age);

		System.out.println(name+age);
		return "success";
	}
}

index.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>Insert title here</title>
</head>
<body>
hello boy

	<form action="login.action" method="post">
		<input type="text" name="name" id="name"></input>
		<input type="text" name="age" id="age">
		<input type="submit" name="sub" value="提交">
	</form>
	<%
		out.println("hello JSP");
		String str="hello ";
	%>
	<%=str %>

	<%
		out.println("jdf<br>");

		application.setAttribute("hello", "hello");
	%>

</body>
</html>

index1.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>Insert title here</title>
</head>
<body>
hello boy

	<form action="TestServlet" method="get">
		<input type="text" name="name" id="name"></input>
		<input type="submit" name="sub" value="提交">
	</form>
	<%
		out.println("hello JSP");
		String str="hello ";
	%>
	<%=str %>

	<%
		out.println("jdf<br>");
	%>

	<%
		String string=request.getParameter("name");
		out.println(string);
		String hello=request.getParameter("age");
		out.println(hello);
	%>
	<br>
	<h1>ok</h1>
	<%
		String name=(String)application.getAttribute("name");
		Integer age=(Integer)application.getAttribute("age");
		out.println(name);
		out.println(age);
	%>
	<s:property value="name"/>
	<s:property value="age"/>
	<h1>ok</h1>
	<%
	String string1=(String)session.getAttribute("name");
	out.println(string1);
	Integer hello1=(Integer)session.getAttribute("age");
	out.println(hello1);
	%>
</body>
</html>

eclipse-整合struts和spring-maven的更多相关文章

  1. 条理清晰的搭建SSH环境之整合Struts和Spring

    上文说到搭建SSH环境所需三大框架的jar包,本篇博客将通过修改配置文件整合Struts和Spring,下篇博客整合Hibernate和Spring即可完成环境搭建. 1.声明bean,新建TestA ...

  2. struts2,hibernate,spring整合笔记(4)--struts与spring的整合

    饭要一口一口吃,程序也要一步一步写, 很多看起来很复杂的东西最初都是很简单的 下面要整合struts和spring spring就是我们的管家,原来我们费事费神的问题统统扔给她就好了 先写一个测试方法 ...

  3. (转)Maven学习总结(六)——Maven与Eclipse整合

    孤傲苍狼只为成功找方法,不为失败找借口! Maven学习总结(六)——Maven与Eclipse整合 一.安装Maven插件 下载下来的maven插件如下图所示:,插件存放的路径是:E:/MavenP ...

  4. Maven学习总结(6)——Maven与Eclipse整合

    Maven学习总结(六)--Maven与Eclipse整合 一.安装Maven插件 下载下来的maven插件如下图所示:,插件存放的路径是:E:/MavenProject/Maven2EclipseP ...

  5. 轻量级Java EE企业应用实战(第4版):Struts 2+Spring 4+Hibernate整合开发(含CD光盘1张)

    轻量级Java EE企业应用实战(第4版):Struts 2+Spring 4+Hibernate整合开发(含CD光盘1张)(国家级奖项获奖作品升级版,四版累计印刷27次发行量超10万册的轻量级Jav ...

  6. Maven+Struts+Hibernate+Spring简单项目搭建

    这段时间学习如何使用Maven+Struts+Hibernate+Spring注解方式建立项目,在这里感谢孙宇老师.    第一次写博客,主要是方便自己查看,同时分享给大家,希望对大家有所帮助,我也是 ...

  7. struts2+hibernate-jpa+Spring+maven 整合(1)

    1.0.0 struts2 与 spring 的整合. 1.1.0 新建maven工程 , 编写pom.xml ,这里只需要简单的添加 一个组件就够了: 在myeclipse 生成的pom.xml 添 ...

  8. Struts2框架04 struts和spring整合

    目录 1 servlet 和 filter 的异同 2 内存中的字符编码 3 gbk和utf-8的特点 4 struts和spring的整合 5 struts和spring的整合步骤 6 spring ...

  9. Maven学习总结(六)——Maven与Eclipse整合

    一.安装Maven插件 下载下来的maven插件如下图所示:,插件存放的路径是:E:/MavenProject/Maven2EclipsePlugin

  10. spring3+struts2+hibernate3整合出现的问题,No mapping found for dependency [type=java.lang.String, name='struts.objectFactory.spring.enableAopSupport']

    七月 11, 2016 3:49:24 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRule ...

随机推荐

  1. Linux 高性能服务器编程——I/O复用

    问题聚焦:     前篇提到了I/O处理单元的四种I/O模型.     本篇详细介绍实现这些I/O模型所用到的相关技术.     核心思想:I/O复用 使用情景: 客户端程序要同时处理多个socket ...

  2. FFmpeg在Linux下安装编译过程

    转载请把头部出处链接和尾部二维码一起转载,本文出自:http://blog.csdn.net/hejjunlin/article/details/52402759 今天介绍下FFmpeg在Linux下 ...

  3. 有n个数,输出其中所有和为s的k个数的组合。

    分析:此题有两个坑,一是这里的n个数是任意给定的,不一定是:1,2,3...n,所以可能有重复的数(如果有重复的数怎么处理?):二是不要求你输出所有和为s的全部组合,而只要求输出和为s的k个数的组合. ...

  4. SQL Server专家的10个秘诀(翻译加注解)

    当你点开这篇文章的时候,如果觉得没有读下去的必要,也希望你能拉到最后看看那几行字! 原文出处:https://technet.microsoft.com/en-us/magazine/gg299551 ...

  5. JAVA面向对象-----final关键字

    JAVA面向对象-–final关键字 1:定义静态方法求圆的面积 2:定义静态方法求圆的周长 3:发现方法中有重复的代码,就是PI,圆周率. 1:如果需要提高计算精度,就需要修改每个方法中圆周率. 4 ...

  6. XML之DOM解析模型

    <?xml version= "1.0" encoding = "UTF-8"> <articles> <article cate ...

  7. FFmpeg源代码结构图 - 解码

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  8. Uva - Uva272 - TEX Quotes

    TeX is a typesetting language developed by Donald Knuth. It takes source text together with a few ty ...

  9. Sybase - tempdb

    前沿:换了新公司,公司使用的Sybase数据库.现在开始学习Sybase数据库了.希望未来的几个月能对Sybase由浅入深的了解和研究. Tempdb的作用 sybase server端内部使用 排序 ...

  10. sql的索引:网上看到不错,整理成自己的东西

    数据库建立索引可以提高查询速度.假如我们创建了一个 mytable表: CREATE TABLE mytable(ID INT NOT NULL,username VARCHAR(16) NOT NU ...