Struts2之2.5.10配置

  struts2开发环境搭建,环境eclipse + struts 2.5.10 + Tomcat 9

1、eclipse下新建web工程

2、将jar包拷贝到WEB-INF/lib下

3、配置struts.xml 和web.xml【这两个文件可以在下载struts2时struts-2.5.10.1-apps中得到,解压这里面的war包在相应位置能找到,包括这里没有写得log4j2.xml】

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">

<struts>
    <package name="default" extends="struts-default">
        <action name="helloWorld" class="com.marost.action.HelloWorldAction" method="excute">
            <result name="success">/WEB-INF/page/hello.jsp</result>
        </action>
    </package>
</struts>

web.xml

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

<web-app id="starter" version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <display-name>Struts 2 Rest Example</display-name>

  <!-- Filters -->
  <!-- START SNIPPET: filter -->
    <filter>
        <filter-name>action2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <!-- END SNIPPET: filter -->

    <filter-mapping>
        <filter-name>action2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Welcome file lists -->
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <!-- Restricts access to pure JSP files - access available only via Struts action -->
    <security-constraint>
        <display-name>No direct JSP access</display-name>
        <web-resource-collection>
            <web-resource-name>No-JSP</web-resource-name>
            <url-pattern>*.jsp</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>no-users</role-name>
        </auth-constraint>
    </security-constraint>

    <security-role>
        <description>Don‘t assign users to this role</description>
        <role-name>no-users</role-name>
    </security-role>

</web-app>

4、新建action

package com.marost.action;

public class HelloWorldAction {
    private String msg;

    public String getMessage() {
        return msg;
    }
    public String excute(){
        msg = "你好!";
        return "success";
    }
}

5、新建jsp

在body中输出action中的内容

<%@ 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>
${message }
</body>
</html>

最终的工程结构如下:

访问:http://localhost:8080/Struts2/helloWorld

时间: 2024-07-29 01:04:15

Struts2之2.5.10配置的相关文章

Struts2基于注解的Action配置

使用注解来配置Action的最大优点就是能够实现零配置,可是事务都是有利有弊的.使用方便.维护起来就没那么方便了. 要使用注解方式,我们必须加入一个额外包:struts2-convention-plugin-2.x.x.jar. 虽说是零配置的,但struts.xml还是少不了的,配置例如以下: <? xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apa

华为RH8100V3RAID 10配置

a)华为RH8100V3RAID 10配置 1)开机按照提示按Ctrl+H键进入RAID卡WEBBIOS管理界面: 2)选中“Start”回车,进入RAID卡管理配置界面: 3)移动鼠标到 “configuration wizard”此项,回车: 4)将光标选中第一个 “clear configuration”清除旧的阵列信息: 5)点击“yes”确认. 6)回到菜单选择第二项“new configuration”,点击next如图 7)点击yes即可进入RAID设置进行下一步.选择第一项“ma

struts2中的constant常量配置

struts2中的constant配置详解 本文主要讲解一下struts2中的constant常量配置,内容主要来自于互联网的整理.<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.ap

.NET Core采用的全新配置系统[10]: 配置的同步机制是如何实现的?

配置的同步涉及到两个方面:第一,对原始的配置文件实施监控并在其发生变化之后从新加载配置:第二,配置重新加载之后及时通知应用程序进而使后者能够使用最新的配置.要了解配置同步机制的实现原理,先得从认识一个名为ConfigurationReloadToken的类型开始. [ 本文已经同步到<ASP.NET Core框架揭秘>之中] 目录一.从ConfigurationReloadToken说起二.Configuration对象与配置文件的同步三.应用重新加载的配置四.同步流程总结 一.从Config

struts2之day01——04Struts2相关配置

struts2之day01--04Struts2相关配置 一.Struts2核心配置文件: 1.名称和位置是固定的: 2. 在配置文件中主要的三个标签:package.action.result,标签里面的属性: 二.struts.xml中的三个主要标签 标签package: 1.类似于代码包,区别于不同的action,必须首先写package标签,在package里面才能配置action 2.Package标签属性 (1)name属性: *name属性值根本功能本身没有关系的,在一个配置文件中

(转)struts2.0配置文件、常量配置详解

一.配置: 在struts2中配置常量的方式有三种: 在struts.xml文件中配置 在web.xml文件中配置 在sturts.propreties文件中配置 1.之所以使用struts.propreties文件配置,是因为为了保持与WebWork的向后兼容 2.在实际开发中,在web.xml中配置常量相比其他两种,需要更多的代码量,会降低了web.xml的可读性 3.通常推荐在struts.xml文件中配置struts2的常量,而且便于集中管理 sturt2中搜索加载常量的顺序是: str

基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:2.搭建环境-2.10.配置用户NTF服务

2.10.配置用户NTF服务 2.10.1.配置节点RAC1 1) [[email protected] sysconfig]#sed -i 's/OPTIONS/#OPTIONS/g' /etc/sysconfig/ntpd 2) [[email protected] sysconfig]#cat >> /etc/sysconfig/ntpd << EOF > OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid" &g

Struts2之2.5.10.1HelloWorld

Struts2.5.10.1是目前为止最新的版本,struts2建议持续跟进,理由大家都懂.好了,下面步入正题. 基于struts2.5.10.1建立一个HelloWorld,基于注解的哈! 工具:eclipse neon3,jdk8,tomcat8,windows10(无关紧要) 需要的jar包:struts2官网下载 (1)struts-2.5.10.1-min-lib.zip:用到解压后lib文件夹下的所有jar包: (2)struts-2.5.10.1-all.zip:struts2-c

struts2的执行流程与配置详解

本章主要讲解Struts的执行流程以及Struts的配置以及访问servletApi 全部代码下载: github链接:链接 写文章不易,欢迎大家采我的文章,以及给出有用的评论,当然大家也可以关注一下我的github:多谢: 1.Struts的执行流程: 1.服务器启动时: 加载项目web.xml 创建Struts核心过滤器对象, 执行StrutsPrepareAndExecuteFilter的doFilter 的 init()方法: 在StrutsPrepareAndExecuteFilter