码迷,mamicode.com
首页 > 其他好文 > 详细

Struts2 入门案例

时间:2020-05-28 13:10:54      阅读:48      评论:0      收藏:0      [点我收藏+]

标签:jar   不可   org   ring   xxxx   ace   sof   style   apach   

1:导入对应的核心jar包

技术图片

 

 

2:配置Web

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

    <filter>
        <filter-name>struts</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

        <!-- 默认 Struts2的配置文件Sturts.xml文件是放置于src下 而且是自动加载的 但是可以通过以下可以修改       -->
        <!--  不建议去修改 struts.xml默认放置路径   不建议配置 init-param 最好直接放置在src下    -->
        <init-param>
            <param-name>config</param-name>
            <!--例如放置在configs文件下-->
            <param-value>struts-default.xml,struts-plugin.xml,configs/struts.xml</param-value>
        </init-param>
        <!--    .............    -->
        
    </filter>
    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

3:配置一个简单的struts.xml文件   文件名不可修改(因为框架内部代码是直接找 struts.xml的)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "struts-2.1.dtd" >

<struts>
    <package name="xxxxx" extends="struts-default" namespace="/">
        <action name="helloWorld" class="com.cn.Hello" method="hell">
            <result name="h" >/index.jsp</result>
        </action>
    </package>

</struts>

4:编写一个java类

package com.cn;

public class Hello {
    public String hell(){
        System.out.println("hello world..................");
        return "h";
    }
}

5:启动tomcat运行第一个helloworld

     http://localhost:8080/Re_Servlet/helloWorld

Struts2 入门案例

标签:jar   不可   org   ring   xxxx   ace   sof   style   apach   

原文地址:https://www.cnblogs.com/gaoSJ/p/12979685.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!