今天遇到个非常奇怪的问题。
在<a>中写链接,但发现java代码不能顺利解析了,不知道为什么!!非常奇怪!
出事代码:<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>    
    <title>成功登录</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
  </head>
  
  <body>
    <h1>成功登录</h1>
    <div>
     <div>选择操作</div>
     <ul>
     <li> <a href="<%=request.getContextPath() %>/imoperation.action">操作</a> </li>
     </ul>
    </div>
  </body>
</html>
<a href="<%=request.getContextPath() %>/imoperation.action">操作</a>
服务器转为html后解析为:
http://localhost:8080/paymentWeb/<%=request.getContextPath()%20%>/imoperation.action这是怎么回事啊,早上还好好的???

解决方案 »

  1.   

     <a href="<%=request.getContextPath() %>/imoperation.action">错误
     <a href="imoperation.action">正确
      

  2.   

    ... 是struts2模板出现问题不是jsp的原因,叫同事一起看了老半天,唉,不细心惹的祸
      

  3.   

    jsp中一般都会自带以下代码<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    你只要在<head>下加上一下代码
      <base href="<%=basePath%>">
    后面的就只要写成
    <a href="imoperation.action">
    就可以了