• 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

  • 相关阅读:
    [转]How can I create a design netlist without including my source design files?
    [转]基于FPGA的以太网开发
    [转]GMII/RGMII/SGMII/TBI/RTBI接口信号及时序介绍
    [原]Altium画PCB时鼠标十字不能对准焊盘中心
    [转]Altera特殊管脚的使用(适用全系列Altera FPGA,MSEL区别除外)-来自altera论坛
    [转]STM32正交编码器驱动电机
    [转]使用D触发器制作正交编码器的鉴相电路
    [转]解决STM32开启定时器时立即进入一次中断程序问题
    [转]ISE iMPACT bit生成mcs
    [转]NiosII处理器软件代码优化方法
  • 原文地址:https://www.cnblogs.com/ShawnYang/p/6670500.html
Copyright © 2020-2023  润新知