zoukankan      html  css  js  c++  java
  • Struts2 Namespace_命名空间

      namespace决定了action的访问路径,默认为"",可以接受所有路径的action

      amespace可以写为/,或者/xxx,或者/xxx/yyy,对应的action访问路径为/index.action,/xxx/index.action,或

    者/xxx/yyy/index.action

      namespace最好也用模块来进行命名

    ----------------------------------Hongten----------------------------------- 

    新建项目web project:struts2_0200_Namespace

    Build Path:引入struts2的jar包

    struts.xml

    代码:

    <?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.devMode" value="true"/>
        <package name="front" namespace="/" extends="struts-default">
            <action name="index">
                <result name="success">/Namespace.jsp</result>
            </action>
        </package>

      <package name="main" extends="struts-default" namespace="">
            <action name="index">
                <result>/Namespace.jsp</result>
            </action>
        </package>
    </struts>

    ----------------------------------Hongten----------------------------------- 

    注解:

        package:用来区分重名的情况

        namespace:必须用"/"开头,如:/front ,在url中我们就要输入:http://localost:1000/struts2_0200_Namespace/front/index.action

      package和namespace在开发的时候都以模块来命名。

        result:凡是name="success"的result,都可以不写:name="success"即:<result>/Namespace.jsp</result>

    ----------------------------------Hongten----------------------------------- 

     Namespace.jsp

    代码:

    <?xml version="1.0" encoding="GB18030" ?>
    <%@ page language="java" contentType="text/html; charset=GB18030"
        pageEncoding="GB18030"%>
        <%@taglib uri="/struts-tags" prefix="s" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
    <title>Insert title here</title>
    </head>
    <body>
    namespace决定了action的访问路径,默认为"",可以接收所有路径的action<br />
    namespace可以写为/,或者/xxx,或者/xxx/yyy,对应的action访问路径为/index.action,
    /xxx/index.action,或者/xxx/yyy/index.action.<br/>
    namespace最好也用模块来进行命名
    </body>
    </html>

    ----------------------------------Hongten----------------------------------- 

    感谢:尚学堂-马士兵

    ----------------------------------Hongten----------------------------------- 


     

  • 相关阅读:
    安装thrift时,注意openssl参数
    Linux下boost编译安装
    super-smack
    算术运算指令
    C/C++中有关字长与平台无关的整数类型
    URLTester2.3.2
    第20课 链接过程简介
    第19课 编译过程简介
    第18课 三目运算符和逗号表达式
    第17课 ++和--操作符分析
  • 原文地址:https://www.cnblogs.com/hongten/p/2121450.html
Copyright © 2011-2022 走看看