第一个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. @ResponseBody 返回乱码 的解决办法

    1:最快的  最简单的办法是  在Ajax请求脸面指定头信息Accept属性,StringHttpMessageConverter默认iso-8859-1编码,但是会根据请求头信息指定的编码格式来转换 ...

  2. 《HTTP权威指南》3-HTTP报文

    报文流 HTTP报文是在HTTP应用程序之间发送的数据块,这些数据块以文本形式的元信息开头,这些信息描述了报文的内容及含义,后面跟着可选的数据部分.这些报文在客户端,服务器和代理之间流动. 报文的组成 ...

  3. iOS 计算所有标注的经纬度范围 来确定地图显示区域

    1.计算所有点的经纬度范围 //向点聚合管理类中添加标注 _imageDataArr是存放经纬度标注数组 for (NSInteger i = 0; i < _imageDataArr.coun ...

  4. Redis安装和实际应用

    上次介绍了Redis的来龙去脉以及相关一些情况,点击回顾<深入浅出Redis>,接下来我们再讲讲Redis的安装和实际应用. 一.Redis的安装 下载安装包,redis-3.2.9.ta ...

  5. OkHttp 设置 User-Agent 教程

    我们知道OkHttp走的并不是原生的http请求,因此在header里面并没有真正的User-Agent,而是“okhttp/版本号”这样的字符串,因为后台需要统计信息,要求传入正确的User-Age ...

  6. 每天学点SpringCloud(十一):Hystrix仪表盘

    在SpringCloud学习系列博客第六篇文章中,我们已经学习了Hystrix的使用,但是那篇文章中有一点遗漏没有讲,那就是Hystrix Dashboard ,它可以实时的监控Hystrix的运行情 ...

  7. 110道python面试笔试题汇总,你能答对几道?

    数据分析系列教程插播一篇面试题教程,最近公众号新来了不少朋友,这几天不少粉丝留言说问我有没有python面试题,其实之前分享过一些面试题,今天统一再给大家分享一遍,也希望能帮助此时仍在找工作的同学,尽 ...

  8. Rpc框架dubbo-server(v2.6.3) 源码阅读(一)

    额,dubbo的前世今生咱就不说了,有用的人都知道.(最新版本已更名 incubator-dubbo,预计版本3.0,不过咱们就先不掺和别人的开发过程了,以v2.6.3为蓝本) 首先,是工作需要,用到 ...

  9. 对称加密AES

    static void Main(string[] args) { //string str = "rqiJI7eEICT+YZmScpAdbjzLnA4mgL3uU5uHXLBeaE6s8 ...

  10. 【Spark调优】聚合操作数据倾斜解决方案

    [使用场景] 对RDD执行reduceByKey等聚合类shuffle算子或者在Spark SQL中使用group by语句进行分组聚合时,经过sample或日志.界面定位,发生了数据倾斜. [解决方 ...