Struts2中 Path (getContextPath与basePath)
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)的更多相关文章
- jsp中的<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...
- String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...
- <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...
- 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 ...
- 关于String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
关于 String path = request.getContextPath(); String basePath = request.getScheme()+"://"+req ...
- struts2中把action中的值传递到jsp页面的例子
例子: RegistAction的代码: package com.wss.action; import javax.servlet.http.HttpServletRequest; import or ...
- Struts2中配置默认Action
1.当访问的Action不存在时,页面会显示错误信息,可以通过配置默认Action处理用户异常的操作:2.配置方法: 在struts.xml文件中的<package>下添加如下内容: ...
- Struts2中属性驱动与模型驱动
属性驱动: 1.概念 能够利用属性驱动获取页面表单元素的内容 2.步骤 1.在action中声明属性,属性的名称和页面元素中name属性的值保持一致 2.action中的属性必须有set和get方法 ...
- struts2中的路径问题
<?xml version="1.0" encoding="GB18030" ?><%@ page language="java&q ...
随机推荐
- CPM(Cluster Percolation method)派系过滤算法
一.概念 (1)完全子图/全耦合网络/k-派系:所有节点全部两两相连 图1 这些全耦合网络也成为派系,k-派系表示该全耦合网络的节点数目为k 1)k-派系相邻:两个不同的k-派系共享k-1个节点,认为 ...
- Java之IO(零)总结
转载请注明原出处:http://www.cnblogs.com/lighten/p/7274378.html 1.前言 本章是对之前所讲述的整个Java的IO包的一个总结,抽出个人认为比较重要的知识点 ...
- Java之IO(二)BufferedInputStream和BufferedOutputStream
转载请注明源出处:http://www.cnblogs.com/lighten/p/6971234.html 1.前言 本文主要介绍输入输出流中的BufferedInputStream和Buffere ...
- LetExpr表达式解读
Integer a = 0; a++; 举个例子,如下: package com.test19; public class BugReport<T> { private T n; publ ...
- 解决chrome,下载在文件夹中显示,调用错误的关联程序
https://blog.csdn.net/qq_32337527/article/details/81778732?utm_source=blogxgwz0
- CFLAGS CPPFLAGS CPPFLAGS 区别
CPPFLAGSC预处理器参数.( C 和 Fortran 编译器也会用到). CXXFLAGSC++语言编译器参数. CFLAGSC语言编译器参数.
- elasticsearch 导入基础数据并索引之 geo_shape
我们看到的图形, 实际是由点来完成的, 有2种类型的格子模型可用于地理星座, 默认使用的是geoHash, 还有一种4叉树(quad trees), 也可用于 判断形状与索引的形状关系 1), int ...
- jQuery为图片添加链接(创建新的元素来包裹选中的元素)
主要用到 wrap()函数 http://www.w3school.com.cn/jquery/manipulation_wrap.asp 这个函数是创建新的的元素去包裹所执行这个方法的元素 如下例子 ...
- 面试题20:搜索二叉树可能有两个元素发生了交换,如何恢复BST?
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...
- APP消息推送机制的实现(PUSH)
出于好奇,想了解一下消息推送机制,在网上搜索到了几篇文章,感觉还不错,粘贴下来,等真正用到的时候再仔细研究 以下两篇是关于ios的 1.http://blog.csdn.net/xyxjn/artic ...