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>

Struts2中 Path (getContextPath与basePath)的更多相关文章

  1. jsp中的<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

    <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...

  2. String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!

    <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...

  3. <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

    <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...

  4. jsp页面String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!

    转自:https://blog.csdn.net/kiwangruikyo/article/details/81130311 <%String path = request.getContext ...

  5. 关于String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

    关于 String path = request.getContextPath(); String basePath = request.getScheme()+"://"+req ...

  6. struts2中把action中的值传递到jsp页面的例子

    例子: RegistAction的代码: package com.wss.action; import javax.servlet.http.HttpServletRequest; import or ...

  7. Struts2中配置默认Action

    1.当访问的Action不存在时,页面会显示错误信息,可以通过配置默认Action处理用户异常的操作:2.配置方法:    在struts.xml文件中的<package>下添加如下内容: ...

  8. Struts2中属性驱动与模型驱动

    属性驱动: 1.概念 能够利用属性驱动获取页面表单元素的内容 2.步骤 1.在action中声明属性,属性的名称和页面元素中name属性的值保持一致 2.action中的属性必须有set和get方法 ...

  9. struts2中的路径问题

    <?xml version="1.0" encoding="GB18030" ?><%@ page language="java&q ...

随机推荐

  1. 【xsy1147】 异或(xor) 可持久化trie

    我的脑回路可能比较奇怪. 我们对这些询问离线,将所得序列${a}$的后缀和建$n$棵可持久化$trie$. 对于一组询问$(l,r,x)$,我们在主席树上询问第$l$棵树$-$第r$+1$棵树中与$s ...

  2. win7安装docker报错:error during connect: Get http ..... the system cannot find the file specified

    因为是win7 所以使用了官方网站的dockertoolbox 安装一路顺利,结果启动就报上面的错误, 因为安装包附带安装了virtualbox 上面的错误后来排查出来是 virtualboox的问题 ...

  3. 删除Open with Atom右键菜单

    特别特别讨厌Atom的右键菜单,叕没有设置项可以去掉,烦!安装完RegScanner v2.15汉化版之后,开始搜索删除Atom的右键菜单 1.打开E:\RegScanner2.加载配置文件 E:\R ...

  4. 【链表】Insertion Sort List

    题目: Sort a linked list using insertion sort. 思路: 插入排序是一种O(n^2)复杂度的算法,基本想法相信大家都比较了解,就是每次循环找到一个元素在当前排好 ...

  5. 关于C++中操作符重载的疑问 :四个运算符=, -&gt;, [], ()不可以重载为全局函数(友员函数)

    转载自:http://blog.csdn.net/u014610226/article/details/47679323     以下是对C++中不能重载为友元函数的四个运算符进行了详细的分析介绍,需 ...

  6. C51单片机中data、idata、xdata、pdata的区别

    C51单片机中data.idata.xdata.pdata的区别 data: 固定指前面0x00-0x7f的128个RAM,可以用acc直接读写的,速度最快,生成的代码也最小. idata: 固定指前 ...

  7. Java性能调优:利用VisualVM进行性能分析

    JVisualVM 简介 VisualVM 是Netbeans的profile子项目,已在JDK6.0 update 7 中自带,能够监控线程,内存情况,查看方法的CPU时间和内存中的对 象,已被GC ...

  8. 电信固定ip宽带80与8080端口踩坑

    本文只是作为记录,避免后面遇到此类问题耗费时间. 实际情况:公司有个固定电信宽带是固定IP的,想把固定IP映射到测试环境ip,实现可以公网通过固定ip访问,内网通过局域网ip访问. 测试环境服务是占用 ...

  9. ZooKeeper:架构和算法

    ZooKeeper主要用来解决分布式应用场景中存在的一些问题,如:统一命名服务.状态同步服务.集群管理.分布式应用配置管理等. 它支持Standalone模式和分布式模式,在分布式模式下,能够为分布式 ...

  10. Ubuntu18.0.4查看显示器型号

    在官网https://launchpad.net/ubuntu/+source/xresprobe下载二进制包,apt-get目前无法安装xresprobe 输入命令sudo ddcprobe 得到如 ...