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

    namespace决定了action的访问路径,默认为"",可以接受所有路径的action
     
      namespace可以写为/,或者/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>

  • 相关阅读:
    读《猫城记》 | 人间失格
    如果这都算是佛系
    常规流(Normal flow)
    页面重绘(repaint)和回流(reflow)
    display:none和visiblity:hidden区别
    读《人类简史》 | 一本很值得读的书
    Mac shell笔记
    读《围城》
    珠海游记
    mouseout、mouseover和mouseleave、mouseenter区别
  • 原文地址:https://www.cnblogs.com/CosyAndStone/p/3827248.html
Copyright © 2011-2022 走看看