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. JS: 防抖节流

    防抖节流 防抖(debounce) 先来看看下面的代码: //触发滚动事件,num 就加1 let num = 0; function incNum() { console.log('鼠标滚动中'); ...

  2. POJ 1032

    #include<iostream> using namespace std; int main() { int n; int num; ; int i,j; cin>>num ...

  3. KMP-字符串模式匹配(c++/python实现)

    KMP算法可以在O(n+m)的时间数量级上完成模式匹配,其做法在于:没当一次匹配过程中出现字符比较不等时,不需要回溯指针,而是利用已经得到的“部分匹配”的结果将模式向右“滑动”尽可能远的一段距离后,继 ...

  4. 【树】Convert Sorted Array to Binary Search Tree

    题目: Given an array where elements are sorted in ascending order, convert it to a height balanced BST ...

  5. ES6-let、const和块级作用域

    1.介绍 总的来说,ES6是在ES2015的基础上改变了一些书写方式,开放了更多API,这样做的目的最终还是为了贴合实际开发的需要.如果说一门编程语言的诞生是天才的构思和实现,那它的发展无疑就是不断填 ...

  6. WPF设置控件获得焦点FocusManager

      简单用法如下: 在父类容器中通过附加属性FocusManager.FocusedElement来绑定需要强制获得焦点的控件,用法如下: <Grid FocusManager.FocusedE ...

  7. 从入门到不放弃系列之Koa2

    一.Koa2入门 本来是想Express入门的,但是既然都是要学,干嘛不学最新的呢? 其实我想说,我本来只是想学个小程序开发,现在已经陆陆续续开了好多坑了.. 本文参考廖雪峰教程 二.Async 最新 ...

  8. Java 注解实例

    package com.annotation; import java.lang.annotation.Retention; import java.lang.annotation.Target; i ...

  9. java内存中的对象

    前记:几天前,在浏览网页时偶然的发现一道以前就看过很多遍的面试题,题目是:“请说出‘equals’和‘==’的区别”,当时我觉得我还是挺懂的,在心里答了一点(比如我们都知道的:‘==’比较两个引用是否 ...

  10. UML——六大关系整理

    UML——六大关系整理 1.定义 是一种面向对象的建模语言,它是运用统一的.标准化的标记和定义实现对软件系统进行面向对象的描述和建模(百度百科). 2.六种关系 这六种关系分别为,继承.实现.关联.聚 ...