Struts2学习笔记——Namespace

来源:互联网 发布:做淘宝店铺用什么软件 编辑:程序博客网 时间:2024/04/23 23:35
namespace决定了action的访问路径,默认为"",可以接收所有路径的action
namespace可以写为/,或者/xxx,或者/xxx/yyy,对应的action访问路径为/index.action,/xxx/index.action,或者/xxx/yyy/index.action.

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

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>  <constant name="struts.devMode" value="true" />  <package name="front" namespace="/front" extends="struts-default">       <!--  <default-action-ref name="index" /> -->       <!-- 配置默认的访问路径 -->        <action name="index">            <result> /Namespace.jsp  </result>        </action>    </package>        <package name="main" namespace="" extends="struts-default">       <!--  <default-action-ref name="index" /> -->       <!-- 配置默认的访问路径 -->        <action name="index">            <result>                /Namespace.jsp            </result>        </action>    </package>      <!-- Add packages here --></struts>
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>
然后我们在访问http://localhost:8080/Struts2_0200_Namespace/index和http://localhost:8080/Struts2_0200_Namespace/front/index的时候都可以访问到我们的Namespace.jsp

0 0
原创粉丝点击