zoukankan      html  css  js  c++  java
  • struts2基础

    1、下载struts2源码包:http://struts.apache.org/download.cgi

    必需包:

    2、新建web项目

     3、配置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="hello" namespace="/" extends="struts-default">
             <action name="HelloWorld" class="com.struts2.action.HelloWorld">
                <result>helloWorld.jsp</result>
            </action>
         </package>
    </struts>

    需要注意这里的是xml中的struts的版本号应该与项目struts2.jar包一致

    4、配置web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
      <display-name>struts2</display-name>
      
      <!-- 
      StrutsPrepareAndExecuteFilter类是Struts2的控制器,用于过滤
         客户端的所有请求。它是Struts2框架的入口,如果未在web.xml
         中进行配置,Struts2框架就会失去其作用
      
       -->
      <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>*.action</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>

    5、在tomcat中启动项目

    6、访问:http://localhost:8080/struts2/HelloWorld.action

  • 相关阅读:
    ci 框架 报错级别 调整
    首页流氓广告的一种实现方法
    php中实现中文字符串的反转
    vmware 1021 错误解决 win7 64位
    isset 判断为POST信息是否为空 (笔记,持续更新)
    windows 下 ci 框架 命令行模式(cli)的使用
    ci 框架 excel 上传失败的处理
    php 日期处理(不断更新)
    svn的本地密码文件处理
    rpmdb open failed 的解决办法
  • 原文地址:https://www.cnblogs.com/x-jingxin/p/8447190.html
Copyright © 2011-2022 走看看