zoukankan      html  css  js  c++  java
  • Struts相关

    使用Struts2流程:

    1.导入Struts2类包

    2.在Web源代码文件夹中,创建名为struts.xml的配置文件。在其中定义Action对象,其关键代码如下:

    struts.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="Mypackage" namespace="/" extends="struts-default">
        <!-- 定义Action -->
        <action name="first">
            <!-- 定义处理成功后的映射界面 -->
            <result>/first.html</result>
        </action>
    </package>
    </struts>

    3.在web.xml文件中声明Struts2提供的过滤器,类名为"org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter"

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
      <display-name>Struts2First</display-name>
      <filter>                            <!-- 配置Struct2过滤器 -->
          <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>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
    </web-app>

    4.初始界面index.jsp:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <a href="first.action">跳转</a>     <!-- 点击链接后,请求交给名为first的Action处理 -->  
    </body>
    </html>

    5.处理后的映射界面first.jsp:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    我的第一个struts2实例
    </body>
    </html>
  • 相关阅读:
    telnet命令测试端口连接是否正常, telnet不是内部或外部命令的方案
    Linux常用命令
    nginx的反向代理的优势,特点于原理(一)
    linux操作系统中的常用命令以及快捷键(一)
    Centos网卡名称命名
    Centos第一次使用配置IP地址
    Linux环境下交叉编译器安装及运行
    jupyter更换路径
    python3实现在二叉树中找出和为某一值的所有路径
    使用 SQL 服务器时,"评估期已过期"错误消息
  • 原文地址:https://www.cnblogs.com/zjlyyq/p/6104855.html
Copyright © 2011-2022 走看看