今天遇到个非常奇怪的问题。
在<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这是怎么回事啊,早上还好好的???
在<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这是怎么回事啊,早上还好好的???
<a href="imoperation.action">正确
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
你只要在<head>下加上一下代码
<base href="<%=basePath%>">
后面的就只要写成
<a href="imoperation.action">
就可以了