Struts2_Path
路径问题说明:
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的更多相关文章
随机推荐
- MVC与三层的区别
闲来无事,想了想MVC与三层的区别,根据自己的经验,上图 由此来看,其实这两种框架(结构)的分层方式其实没什么联系,也没有什么可比性,但他们的目的都一样的:解耦 --Ones
- php实现页面跳转的几种方式
PHP中实现页面跳转有一下几种方式,看了几个人写的不是很条理,自己整理一下 在PHP脚本代码中实现 <?php header("location:url地址") ?> ...
- 安装OFFICE2016错误代码0-1018(0)的解决方案 和激活方案
一.安装OFFICE2016错误代码0-1018(0)的解决方案 下面方法亲测有效:Step 1. Go to C:\Program Files\Common Files\microsoft shar ...
- Canvas制作动态进度加载水球
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- lintcode - 统计比给定整数小的数的个数(两种方法)
class Solution { public: /* * @param A: An integer array * @param queries: The query list * @return: ...
- etcd介绍
etcd是一个开源的.分布式的键值对数据存储系统,提供共享配置.服务的注册和发现. etcd与zookeeper相比算是轻量级系统.etcd的raft比zookeeper的paxos简单. 我们用et ...
- windows环境搭建禅道项目管理工具
zentao官网的几个网址 http://www.zentao.net/ http://www.zentao.net/article-view-79863.html 搭建环境需要下载两个文件 1) ...
- ArrayList中进行删除操作引发的问题
1.普通for遍历 for(int i=0;i<list.size();i++){ if(list.get(i).equals("a")) list.remove(i); } ...
- MyCnblog Style
以下内容添加到页脚HTML代码处 <style> #leftmenu ul { display: none; } .cnblogs-markdown pre code, .cnblogs- ...
- RTT设备与驱动之PIN设备
单片机的PIN有2个基本功能:GPIO和AFIO,其中gpio的常用功能: 1 输入:上拉.下拉.模拟.浮动 2 输出:上拉.下拉.推挽.开漏 3 中断:上升沿.下降沿.双沿.高电平.低电平触发 RT ...