struts2之namespace

来源:互联网 发布:淘宝的图片 编辑:程序博客网 时间:2024/05/18 10:46

1.struts.xml

<span style="font-size:18px;"><?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>    <!-- Add packages here -->     <constant name="struts.devMode" value="true" /><package name="default"<span style="color:#ff0000;"> namespace="/"</span> extends="struts-default">        <action name="hello">            <result>            /Hello.jsp            </result>        </action>    </package></struts></span>
说明:namespace可以为"/",也可以为空,也可以为/xxx/xxx.action等,这样的话访问的路径就会有所不同。这个点需要注意,如果访问路径中namespace写错,编译器就会报there is no action......的异常。
2.hello.jsp

<span style="font-size:18px;"><%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>HelloStruts2</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">-->  </head>    <body>    Hello Struts2 <br>  </body></html></span>


0 0
原创粉丝点击