• Struts2 入门案例


    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

    坚持
  • 相关阅读:
    淘淘商城项目分析报告
    LDAP入门
    spring APO的简单理解
    MySQL数据库的导入导出
    servlet CDI
    Result 架构
    java的设计模型
    JavaEE人力资源管理系统测试报告——许珍源、朱国辉小组
    部分代码片段——人力资源管理系统
    期末项目——人力资源管理系统需求分析
  • 原文地址:https://www.cnblogs.com/gaoSJ/p/12979685.html
Copyright © 2020-2023  润新知