• Java-struts2 配置hellow world


    这里进行struts框架的配置问题,和简单的输出hellow world

    配置的步骤

    1.      配置TomCat

    2.      JDK

    3.      拷贝struts.xml文件到src目录

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
    
    <struts>
    	<!-- 
        <constant name="struts.enable.DynamicMethodInvocation" value="false" />
        <constant name="struts.devMode" value="false" />
    
        <include file="example.xml"/>
    
    
    
        <package name="default" namespace="/" extends="struts-default">
            <default-action-ref name="index" />
            <action name="index">
                <result type="redirectAction">
                    <param name="actionName">HelloWorld</param>
                    <param name="namespace">/example</param>
                </result>
            </action>
        </package>
    	 -->
    	 
    	 
    	 <constant name="struts.devMode" value="true" />
    	 <package name="default" namespace="/" extends="struts-default">
            
            <action name="hello">
                <result>
                    /Hello.jsp
                </result>
            </action>
        </package>
        <!-- Add packages here -->
    
    </struts>
    

    4.      拷贝jar文件包到lib目录下

    随便去网上下一个struts2 的包,然后解压就能够得到想要的文件

    可以到这个地址去下载http://struts.apache.org/download.cgi

    5.      配置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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>Struts</display-name>
      <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>
      
        <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>/*</url-pattern>
        </filter-mapping>
    
    </web-app>
    

    这里是将filter 的内容引入到web.xml里面就行了

    在根目录创建一个Hello.jsp文件,里面写一段测试的"hello world"

    最后在浏览器的地址栏中输入http://localhost:8080/Struts/hello

    就能够打出相应的  "hello world"

    到这里就说明struts2的配置已经完成了

    源码:http://pan.baidu.com/s/1boVgrgV

  • 相关阅读:
    使用JQuery MiniUI,json数据构建TreeGrid(树图)
    Oracle使用plsql连不上本地数据库,cmd中使用sqlplus连的上的可能解决方案
    Oracle数据库存储过程练习20181212
    oracle数据库使用hint来让模糊查询走索引
    java解决动态的锁顺序死锁的方案
    java线程池,信号量使用demo
    [洛谷P3709]大爷的字符串题
    [洛谷P2709]小B的询问
    [NOI2016]区间
    [洛谷P3765]总统选举
  • 原文地址:https://www.cnblogs.com/sunxun/p/3973150.html
Copyright © 2020-2023  润新知