2 qingfenglina11 qingfenglina11 于 2013.07.01 21:34 提问

web开发,jsp界面设计出错
<%@ page language="java" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'error.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>

  <body>
     <font color="#rrddb">操作失败!</font> <br>
  </body>
</html>

显示<%

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

模块出现错误,不知道怎么解决,请求高手。大家帮帮忙啊,在此谢谢了。
如果删除<%

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>就会显示<base href="<%=basePath%>">错误。

3个回答

LiberSapientiae
LiberSapientiae   2013.07.02 01:25
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

这几行擦掉就行~

suannai0314
suannai0314 帮你编辑了下代码部分的格式,更多markdown使用见http://ask.csdn.net/pages/markdown
4 年多之前 回复
sdn346930504
sdn346930504   2013.07.10 20:06

代码没错,你试试关掉文档,清理缓存,再打开,试试~~

<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+ request.getServerName() + ":" + request.getServerPort()+path + "/";%>

request.getScheme() //返回协议名(http)
request.getServerName() //返回IP地址(127.0.0.1)
request.getServerPort() //返回端口号(8080)
request.getContextPath() //返回项目的路径(myweb/admin)

目的是为了得到,请求这个页面的绝对路径

<base href="<%=basePath%>">

的意思是把所有请求都按照这个路径提交.例如有一个超链接

<a href="index.jsp"></a>

那么请求的时候就会是绝对路径http://127.0.0.1:8080/myweb/admin/index.jsp
而不是相对路径。

希望对你有帮助~~~~

z309131664
z309131664   2013.07.10 15:30

<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!