struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径。

虽然可以用redirect方式解决,但redirect方式并非必要。
解决办法非常简单,统一使用绝对路径。(在jsp中用request.getContextpath方式来拿到webapp的路径)
或者使用myeclipse经常用的,指定basePath

例子:

<?xml version="1.0" encoding="GB18030" ?>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<%
    //这里的path是得到webapp的名字,如果我们的webapp名字是struts_0400_path
    //那么path就是struts_0400_path
    //basePath包含了path内容,他是全路径: http://localhost:1000/struts2_0400_paht
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  %>
<!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> 说明:<base href="<%=basePath%>" />是指定根路径。
<base href="<%=basePath%>" /> <meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>Insert title here</title>
</head>
<body>

说明:在这里我们使用的链接是index.jsp,但是因为在<head>中我们定义了<base href="<%=basePath%>" />
  所以在这里的链接其实是:http://localhost:1000/struts2_0400_path/index.jsp 路径

  这就是<base href="<%=basePath%>" />的好处之所在了。
<a href="index.jsp">index.jsp</a>

最新文章

  1. 利用XAG在RAC环境下实现GoldenGate自动Failover
  2. 在UIView上添加tableView设置代理属性
  3. node.js 对接公众平台
  4. unity, sceneview 中拾取球体gizmos
  5. SSH连接问题
  6. 关于6410的sd卡和nandflash启动的区别
  7. php引用详解
  8. C语言中 指针与结构体
  9. 关于python保留几位小数,不进行四舍五入的方法
  10. cloudCompute
  11. Servlet的学习(三)
  12. Android - &amp;quot;cause failed to find target android-14&amp;quot; 问题
  13. C语言实例:结构体
  14. CRM-展示列表,分页功能
  15. hana-banach定理
  16. 【NET Core】 缓存 MemoryCache 和 Redis
  17. VC++ 获取Windows系统版本号、CPU名称
  18. [Leetcode]123.买卖股票的最佳时机3
  19. 一款经典的 jQuery Lightbox 灯箱效果
  20. linux下如何删除十字符libudev.so病毒文件

热门文章

  1. 【BZOJ2127】happiness 最小割
  2. 5、xamarin.android 中如何对AndroidManifest.xml 进行配置和调整
  3. ASP.NET5使用FaceBook登录
  4. sql 递归树
  5. Koa框架教程
  6. Git 什么时候用什么指令
  7. ruby字符串连接
  8. 单点登录(SSO)
  9. [CQOI 2018]交错序列
  10. 阿里云提示ECS服务器存在漏洞处理方法