第一个Struts2程序-Hello

  1.创建web工程struts2-01-Hello

  2.导入jar包到bin目录,jar地址:

  https://files.cnblogs.com/files/aihuadung/struts%E6%89%80%E9%9C%80jar%E5%8C%85.zip

  3.配置web.xml文件

  

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app id="WebApp_ID">

    <display-name>struts2_01_Hello</display-name>

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

    <welcome-file-list>

       <welcome-file>index.html</welcome-file>

       <welcome-file>index.htm</welcome-file>

       <welcome-file>index.jsp</welcome-file>

    </welcome-file-list>

</web-app>

web.xml

  4.src目录下创建struts.xml文件

  5.在index.jsp文件中插入

 <a href="hello.action" method="post">hello.action</a> <br>

  6.创建执行HelloAction的结果文件hello.jsp

  

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <title>hello</title>

   <meta http-equiv="pragma" content="no-cache">

   <meta http-equiv="cache-control" content="no-cache">

   <meta http-equiv="expires" content="0">   

   <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

   <meta http-equiv="description" content="This is my page">

   <!--

   <link rel="stylesheet" type="text/css" href="styles.css">

   -->

  </head>

  <body>

    hello World <br>

  </body>

</html>

hello.jsp

  7.创建HelloAction.java

  

package com.ahd.action;

import com.opensymphony.xwork2.Action;

import com.opensymphony.xwork2.ActionSupport;

public class HelloAction{

         public String execute() throws Exception {

                   // TODO Auto-generated method stub

                   return “SUCCESS”;

         }

}

HelloAction

  8.编辑struts2.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="helloWorld" extends="struts-default" namespace="/">

      <action name="hello" class="com.ahd.action.HelloAction">

        <result name="success">/hello.jsp</result>

      </action>

   </package>

</struts>

struts2.xml

  9.运行结果

  

  点击后

  

struts2_HelloWorld的更多相关文章

  1. 搭建一个简单的Struts2(Struts2_HelloWorld)

    1.导入Jar包 2.配置web.xml 1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-ap ...

  2. [转]初探Struts2.0

    本文转自:http://blog.csdn.net/kgd1120/article/details/1667301 Struts作为MVC 2的Web框架,自推出以来不断受到开发者的追捧,得到用广泛的 ...

  3. Struts2入门学习

    1.Struts2的前身是Opensymphony的Webwork2,实际上Strut和Webwork2合并后形成Struts2.   2.一个HelloWord示例 1)创建Web应用,所需要的Ja ...

  4. Struts2 教程

    一.Struts2是什么 Struts2是在WebWork2基础发展而来的.和Struts1一样, Struts2也是基于MVC的web层框架. 那么既然有了Struts1,为何还要Struts2? ...

  5. Struts2.x教程(一) Struts2介绍

    一.Struts2是什么 Struts2是在WebWork2基础发展而来的.和Struts1一样, Struts2也是基于MVC的web层框架. 那么既然有了Struts1,为何还要Struts2? ...

  6. struts快速入门第一篇 —— struts相关XML配置映射及讲解

    我们回忆一下在学习JavaWeb过程中(Jsp + servlet编程)所感受到的Servlet的不足: 1 Servllet很多时,web.xml中的代码会很多.这样一来,维护起来就不方便,不利于团 ...

  7. Java web struct入门基础知识

    1.Struts2的前身是Opensymphony的Webwork2,实际上Strut和Webwork2合并后形成Struts2.   2.一个HelloWord示例 1)创建Web应用,所需要的Ja ...

  8. Struts和Spring MVC的比较(非原创)

    文章大纲 一.Spring MVC项目例子二.Struts项目例子三.Struts和Spring MVC对比四.参考文章   一.Spring MVC项目例子 https://www.jianshu. ...

随机推荐

  1. MFC之几类消息的区别

    1.ON_COMMAND与ON_UPDATE_COMMAND_UI 开发MFC程序,给菜单子项添加消息处理函数时,会碰到ON_COMMAND和ON_UPDATE_COMMAND_UI两个消息. ON_ ...

  2. C#常用工具类——Excel操作类(ZT)

    本文转载于: http://www.cnblogs.com/zfanlong1314/p/3916047.html /// 常用工具类——Excel操作类 /// <para> ----- ...

  3. Jenkins可用环境变量列表以及环境变量的使用(Shell/Command/Maven/Ant)

    一.可用环境变量列表(以下来自google翻译): BRANCH_NAME 对于多分支项目,这将被设置为正在构建的分支的名称,例如,如果您希望从而master不是从特征分支部署到生产. CHANGE_ ...

  4. Day4:html和css

    Day4:html和css 规范注意 链接里面不能再放链接. a里面可以放入块级元素. 空格规范 选择器与{之间必须包含空格. 如: .class {} 属性名与之后的:符号之间不允许包含空格, 而: ...

  5. StackExchange.Redis 模糊查询和删除

    初始化连接对象 _connectionString = ConfigurationManager.ConnectionStrings["RedisConnectionString" ...

  6. 如何优雅的关闭golang的channel

    How to Gracefully Close Channels,这篇博客讲了如何优雅的关闭channel的技巧,好好研读,收获良多. 众所周知,在golang中,关闭或者向已关闭的channel发送 ...

  7. 小程序第三方框架对比 ( wepy / mpvue / taro )

      众所周知如今市面上端的形态多种多样,手机Web.ReactNative.微信小程序, 支付宝小程序, 快应用等,每一端都是巨大的流量入口,当业务要求同时在不同的端都要求有所表现的时候,针对不同的端 ...

  8. MapReduce中的Join

    一. MR中的join的两种方式: 1.reduce side join(面试题) reduce side join是一种最简单的join方式,其主要思想如下: 在map阶段,map函数同时读取两个文 ...

  9. elasticsearch 操作

    文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html 客户端:https://www.elasti ...

  10. Plugin with id 'com.novoda.bintray-release' not found.的解决方案

    import Module的时候,有时候会提示Plugin with id 'com.novoda.bintray-release' not found. 点击Open File,定位到该Module ...