zoukankan      html  css  js  c++  java
  • Struts2_Path

    路径问题说明:

    struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径。
    index.jsp
    虽然可以用rederect方式解决,但redirect方式并非必要。
    解决办法非常简单,统一使用绝对路径。(在jsp中用request.getContextRoot方式拿到webapp的路径)
    或者使用myeclipse经常使用的,指定basePath。

    index.jsp

     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <%
     4 String path = request.getContextPath();
     5 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
     6 %>
     7 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     8 <html>
     9 <head>
    10 <base href="<%=basePath%>"/>
    11 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    12 <title>首页</title>
    13 </head>
    14 <body>
    15 <h1>Hello World~~~</h1>
    16 <a href="path/path.action">路径问题说明</a>
    17 </body>
    18 </html>

    path.jsp

     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <%
     4 String path = request.getContextPath();
     5 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
     6 %>
     7 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     8 <html>
     9 <head>
    10 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    11 <title>Insert title here</title>
    12 <base href="<%=basePath%>"/>
    13 </head>
    14 <body>
    15 <h1>This is Path.jsp</h1>
    16 struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径。<br>
    17 index.jsp<br>
    18 虽然可以用rederect方式解决,但redirect方式并非必要。<br>
    19 解决办法非常简单,统一使用绝对路径。(在jsp中用request.getContextRoot方式拿到webapp的路径)<br>
    20 或者使用myeclipse经常使用的,指定basePath<br>
    21 <a href="index.jsp">index.jsp</a>
    22 </body>
    23 </html>

    struts.xml

     1 <?xml version="1.0" encoding="UTF-8" ?>
     2 <!DOCTYPE struts PUBLIC
     3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
     4     "http://struts.apache.org/dtds/struts-2.3.dtd">
     5 
     6 <struts>
     7     <constant name="struts.configuration.xml.reload" value="true"/>
     8     
     9     <!-- namespace 必须 "/" 开头 -->
    10     <package name="front" namespace="/path" extends="struts-default">
    11         <action name="path" class="com.bjsxt.struts2.front.action.PathAction">
    12             <result name="path">/path.jsp</result>
    13         </action>
    14     </package>
    15     
    16 </struts>

    链接: http://pan.baidu.com/s/1eSIcqLs 密码: serj

  • 相关阅读:
    Layabox记录坑
    爬虫 Beautifulsoup 常用笔记
    opencv +python 提取roi目标区域全部像素的值 得出上下限 均匀值
    opencv + python 读取像素点 BGRtoRGB 以及注意事项
    pyinstaller打包python+opencv 无法在别人电脑上正常运行 问题所在:opencv_ffmpeg341_64.dll
    python 绝对路径相对路径
    面向对象编程-OOP-一张图看懂类和实例的基本用法
    python3 _笨方法学Python_日记_DAY7
    儋州“炰米”:美味的特制粮食
    PHP学习步骤
  • 原文地址:https://www.cnblogs.com/ShawnYang/p/6670500.html
Copyright © 2011-2022 走看看