路径问题说明:

struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径。
index.jsp
虽然可以用rederect方式解决,但redirect方式并非必要。
解决办法非常简单,统一使用绝对路径。(在jsp中用request.getContextRoot方式拿到webapp的路径)
或者使用myeclipse经常使用的,指定basePath。

index.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页</title>
</head>
<body>
<h1>Hello World~~~</h1>
<a href="path/path.action">路径问题说明</a>
</body>
</html>

path.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<base href="<%=basePath%>"/>
</head>
<body>
<h1>This is Path.jsp</h1>
struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径。<br>
index.jsp<br>
虽然可以用rederect方式解决,但redirect方式并非必要。<br>
解决办法非常简单,统一使用绝对路径。(在jsp中用request.getContextRoot方式拿到webapp的路径)<br>
或者使用myeclipse经常使用的,指定basePath<br>
<a href="index.jsp">index.jsp</a>
</body>
</html>

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.configuration.xml.reload" value="true"/> <!-- namespace 必须 "/" 开头 -->
<package name="front" namespace="/path" extends="struts-default">
<action name="path" class="com.bjsxt.struts2.front.action.PathAction">
<result name="path">/path.jsp</result>
</action>
</package> </struts>

链接: http://pan.baidu.com/s/1eSIcqLs 密码: serj

Struts2_Path的更多相关文章

随机推荐

  1. 洛谷 P2982 [USACO10FEB]慢下来Slowing down

    题目描述 Every day each of Farmer John's N (1 <= N <= 100,000) cows conveniently numbered 1..N mov ...

  2. vue.js路由学习笔记二

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  3. svn显示提交人以及时间

    eclipse使用svn显示提交人以及提交时间,方便查看自己修改过的代码,过程如下: Window-->Preferences-->Team-->SVN-->Lable dec ...

  4. POJ1057 FILE MAPPING

    题目来源:http://poj.org/problem?id=1057 题目大意:计算机的用户通常希望能够看到计算机存储的文件的层次结构的图形化表示.Microsoft Windows的 " ...

  5. C语言中类型限定符

    通常用类型和存储类别来描述一个变量. C90还增加了两个属性:恒常性(constancy).易变性(volatility): 分别用关键字const和volatile来声明. 这两个关键字创建的类型是 ...

  6. AngularJs 中使用OpenLayer例子,手机端地图加载不显示问题

      var map, toolip, overlay;            var layer = new ol.layer.Vector();            var imgLayer = ...

  7. UVALive 3645 时序模型

    按航班拆点 注意返边的条件 #include<bits/stdc++.h> using namespace std; const int maxn = 1e6+11; const int ...

  8. linux学习五

    一.系统服务管理 1.概念 服务(service) 本质就是进程,但是是运行在后台的,通常都会监听某个端口,等待其它程 序的请求,比如(mysql , sshd 防火墙等),因此我们又称为守护进程,是 ...

  9. 安装openstack时遇到的错误

    学习opensatck的第一步是安装DevStack来进行本机操作 1. 下面命令没有权限,解决办法:切换到root用户下执行sudo -s echo "stack ALL=(ALL) NO ...

  10. app常见测试点

    安装与卸载: ●应用是否可以在IOS不同系统版本或android不同系统版本上安装(有的系统版本过低,应用不能适配) ●软件安装后是否可以正常运行,安装后的文件夹及文件是否可以写到指定的目录里. ●安 ...