开发者社区> 问答> 正文

未找到方法(FUNCTION_NOT_FOUND):request.contextPath?报错

@闲大赋 你好,想跟你请教个问题:

我的html中是这样写的:

<!DOCTYPE html>
<%
var path = request.contextPath();
var basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
var url = basePath + "ssl/loanConfirm.htm?loanId=";
print(path);
%>
<html>

但是浏览页面时却报错说没有contextPath这个方法~

展开
收起
爱吃鱼的程序员 2020-06-09 16:29:16 831 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    直接${ctxPath}就能获得上下文url

    java中,你可以通过request.getContextPath()获取,在模板中,这种getter方法,可以通过属性名获取


    <preclass="brush:java;toolbar:true;auto-links:false;">varpath=request.contextPath;varschema=request.scheme;



    你的代码里,<spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"> request.contextPath<spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"> ( )表示调用一个注册名字为<spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">request.contextPath的方法名,所以会报错,没有找到方法<spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">request.contextPath


    你可以在beetl中按照java习惯调用,但必须以@开头,比如

    <preclass="brush:java;toolbar:true;auto-links:false;">varpath=@reqeust.getContextPath();




    2020-06-09 16:29:34
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
AutoAlerts-From Data to Action 立即下载
OPEN SOURCE IN A DATA-DRIVEN WORLD 立即下载
低代码开发师(初级)实战教程 立即下载