路径问题说明:

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的更多相关文章

随机推荐

  1. linux下将当前目录下的文件名存到一个文本文件里

    如果只是想得到当前目录下(不包括子目录)的相关文件时:ls -l | grep  ".gz$" > 1.txt 如果想得到当前目录下,包括子目录中的相关文件时,应该用find ...

  2. Nginx01---简单使用

    基于腾讯云--ubuntu系统 1.安装nginx sudo apt-get install nginx 2.启动,停止nginx nginx -c /usr/local/nginx/conf/ngi ...

  3. clojure with postgres

    主要关注访问pg.不关心其他db 1 clojure.java.jdbc https://github.com/clojure/java.jdbc http://clojure-doc.org/art ...

  4. 使用windows服务修改CPU型号(重启依然有效)

    此项目基于.net framework 4.0 效果如下: 服务运行前: 服务运行后: 思路大概是这样: 通过修改注册表可以修改CPU型号,把服务设置成本地服务,并且开机自动启动,来实现开机自动修改处 ...

  5. IIS Express被局域网访问

    在 文件夹 C:\Users\administrator\Documents\IISExpress\config 下面 applicationhost.config 文件里 找到相应的项目 如 < ...

  6. Django ORM 最后操作

    F查询:代表2个字段之间的比较 from django.db.models import F models.Book.objects.filter(price__gt=F('keep_price')) ...

  7. delete ELK index

    Go to tab “Dev Tools”4. On the left console type:GET _cat/indices?v&s=store.size:descand execute ...

  8. sublime快捷键:快速查找函数和快速匹配括号

    1. 快速查找函数 Ctrl+R 2. 快速匹配括号 光标置于括号中,Ctrl+Shift+M 快速匹配括号内容,再按下 Ctrl+Shift+[ 折叠代码, Ctrl+Shift+] 展开代码. 3 ...

  9. thinkphp自动验证和自动完成

    tp验证码的自动验证小案例 模板文件 <form action="" method="post"> <p> User: <inpu ...

  10. linux-centos-pgsql-Ident authentication failed for user “postgres”错误出现解决方法

    首先,要找到pg_hba.conf\ -->cd /var/lib/pgsql/data -->vi pg_hba.conf 然后,将里面的配置文件修改如下: # TYPE DATABAS ...