本文主要是介绍struts2之namespace,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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>
这篇关于struts2之namespace的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!