您的位置:首页 > Web前端 > JavaScript

jsp 中 关于获取项目路径问题

2015-05-26 15:00 120 查看
今天调试代码的时候发现个很有意思的问题,测试了好半天也没找到原因,所以只能先记录下来了。

jsp 中代码如下:

<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/common/config.jsp" %>
<title>健康报告</title>

<script>
$(function(){
$("#myTab a").click(function(e){
e.preventDefault();
$(this).tab("show");
});
if($("#item").val()=="base"){
$("a[href='#base']").click();
}
getMealData();
});

/**
* 诊疗报告
*
*/
var getCauseReportData = function(){
var custId=$("#custId").val();
var id=$("#id").val();
var reportDate=$("#reportDate").val();
$.ajax({
url:PublicConstant.basePath+"/page/report/primary_cause_report_query.action", //请求的url地址
dataType:"html", //返回格式为json
async:true,//请求是否异步,默认为异步
data:{"id":id,"reportDate":reportDate,"custId":custId}, //参数值
type:"post", //请求方式
success:function(data){
$("#view").empty();
$("#view").append(data);
}
});
};

/**
* 加载健康树
*/
var getHealthTree = function(){
var custId=$("#custId").val();
var id=$("#id").val();
var reportDate=$("#reportDate").val();
$.ajax({
url:PublicConstant.basePath+"/page/report/healthTreeReport.action", //请求的url地址
dataType:"html", //返回格式为json
async:true,//请求是否异步,默认为异步
data:{"id":id,"reportDate":reportDate,"custId":custId}, //参数值
type:"post", //请求方式
success:function(data){
$("#view").empty();
$("#view").append(data);
}
});
};
/**
* 加载膳食报告
*/
var getMealData = function(){
var custId=$("#custId").val();
var id=$("#id").val();
var reportDate=$("#reportDate").val();
alert(PublicConstant.basePath);
$.ajax({
url:PublicConstant.basePath+"/page/report/meals_report_query.action", //请求的url地址
dataType:"html", //返回格式为json
async:true,//请求是否异步,默认为异步
data:{"id":id,"reportDate":reportDate,"custId":custId}, //参数值
type:"post", //请求方式
success:function(data){
$("#view").empty();
$("#view").append(data);
}
});
};

/**
* 返回到文档页
*/
var returnBack = function(item){
common.pageForward(PublicConstant.basePath+"/page/myarchives/myarchives.action?item="+item);
};
</script>
<script type="text/javascript">
var custId;
var reportDate;
var id;
var custName;

$().ready(function() {
custId=$("#custId").val();
reportDate = $("#reportDate").val();
id=$("#id").val();
custName = $("#custName").val();
});

function repareImp(){
var tempReportDate = new Date(new Date(reportDate).getTime()-24*60*60*1000);
var imgData = [{img : WaterChart.getDataURL(),imgFile : "每日摄入能量分析_水.png"},
{img : NutrientChart.getDataURL(),imgFile : "每日摄入能量分析_产能营养素.png"},
{img : VChart.getDataURL(),imgFile : "每日摄入能量分析_维生素.png"},
{img : MineralChart.getDataURL(),imgFile : "每日摄入能量分析_矿物质.png"},
{img : EnergyChart.getDataURL(),imgFile : "每日摄入能量.png"},
{img : MealsChart.getDataURL(),imgFile : "营养供能比例_实际.png"},
{img : MealsChartT.getDataURL(),imgFile : "营养供能比例_推荐.png"},
{img : MealsEnergyChart.getDataURL(),imgFile : "餐次供能比例_实际.png"},
{img : MealsEnergyChartT.getDataURL(),imgFile : "餐次供能比例_推荐.png"},
{img : MealsAnalysisChart.getDataURL(),imgFile : "膳食结构.png"},
{img : CbrChart.getDataURL(),imgFile : "碳水化合物来源.png"},
{img : ProtidChart.getDataURL(),imgFile : "蛋白质来源.png"},
{img : FatChart.getDataURL(),imgFile : "脂肪来源.png"}
];
var impageParams = {
custId: custId,
reportDate: common.dateFormatToString(new Date(tempReportDate),'yyyyMMdd')
};
var imgUrl = PublicConstant.basePath+"/page/report/saveEchartImg.action";
common.ajaxPost(imgUrl,"params=" + JSON.stringify(impageParams) + "&pdfId=膳食分析报告&imgData="+JSON.stringify(imgData),dataType.json,function(data){
if (!data.result) {
common.alert(data.message, 8);
}else{
printPdfzl();
}
});
}

// 打印
function printPdfzl(){
var params = {
custId : custId, // 各种需要传入的参数列表,JSON格式
exportName : custName+"_医学营养诊疗报告.pdf",// 如需指定导出文件名称,请设置exportName属性
id : id,
reportDate: reportDate,
};
common.ajaxPost(PublicConstant.basePath + "/page/report/exportPdf.action","pdfId=医学营养诊疗报告¶ms="+JSON.stringify(params),dataType.json,function(data){
if (data.result) {
var sFeatures = "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0 channelmode";
window.open(data.value, common.dateFormatToString(new Date(reportDate),'yyyyMMdd'), sFeatures);
} else {
box.alert(data.message, {
title: '提示信息'
});
}
});
};
function printssPdf(){
var custName = $("#custName").val();
var tempReportDate = new Date(new Date(reportDate).getTime()-24*60*60*1000);
tempReportDate=common.dateFormatToString(new Date(tempReportDate),'yyyy-MM-dd');
var custId = $("#custId").val();
var imgData = [{img : WaterChart.getDataURL(),imgFile : "每日摄入能量分析_水.png"},
{img : NutrientChart.getDataURL(),imgFile : "每日摄入能量分析_产能营养素.png"},
{img : VChart.getDataURL(),imgFile : "每日摄入能量分析_维生素.png"},
{img : MineralChart.getDataURL(),imgFile : "每日摄入能量分析_矿物质.png"},
{img : EnergyChart.getDataURL(),imgFile : "每日摄入能量.png"},
{img : MealsChart.getDataURL(),imgFile : "营养供能比例_实际.png"},
{img : MealsChartT.getDataURL(),imgFile : "营养供能比例_推荐.png"},
{img : MealsEnergyChart.getDataURL(),imgFile : "餐次供能比例_实际.png"},
{img : MealsEnergyChartT.getDataURL(),imgFile : "餐次供能比例_推荐.png"},
{img : MealsAnalysisChart.getDataURL(),imgFile : "膳食结构.png"},
{img : CbrChart.getDataURL(),imgFile : "碳水化合物来源.png"},
{img : ProtidChart.getDataURL(),imgFile : "蛋白质来源.png"},
{img : FatChart.getDataURL(),imgFile : "脂肪来源.png"}
];
var impageParams = {
custId:custId,
reportDate: tempReportDate
};
var imgUrl = PublicConstant.basePath+"/page/report/saveEchartImg.action";
common.ajaxPost(imgUrl,"params=" + JSON.stringify(impageParams) + "&pdfId=膳食分析报告&imgData="+JSON.stringify(imgData),dataType.json,function(data){
if (!data.result) {
box.alert(data.message, {
title: '提示信息'
});
}else{
var params = {
custId:custId,
reportDate:tempReportDate,
exportName:custName+"_膳食分析报告.pdf"
};
var exportUrl = PublicConstant.basePath+"/page/report/exportPdf.action";
common.ajaxPost(exportUrl, "pdfId=膳食分析报告¶ms=" + JSON.stringify(params), dataType.json, function(data) {
if (data.result) {
var sFeatures = "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0 channelmode";
var url = PublicConstant.basePath+"/resource/upload/temp/"+common.dateFormatToString(new Date(tempReportDate),'yyyyMMdd')+"/"+custId+"/膳食分析报告/"+custName+"_膳食分析报告.pdf";
window.open(url,common.dateFormatToString(new Date(tempReportDate),'yyyyMMdd'), sFeatures);
} else {
box.alert(data.message, {
title : '提示信息'
});
};
});
}
});
return;
};
// 显示打印报告选择框
function selectReportGroup(){
$("#selectReportGroupModal").modal("show");
}

// 选择要打印的报告
function printSelectedReport(){
var value = $("input:radio[name='reportGroupRadio'][checked='checked']").attr("value");
if(common.isEmpty(value)){
box.alert("请选择报告",{
title : '提示信息'
});
return false;
}else{
$("#selectReportGroupModal").modal("hide");
if(value=="1001"){
printssPdf();
}
if(value=="1002"){
repareImp();
}
}
}
</script>
<style type="text/css">
.table th, .table td{ text-align:center;}
.question-group .question label.question-label{
margin-bottom:50px;
}
.question-group .question{
margin: 20px 20px 0;
width: 880px;
}
.question-group{
margin-left:30px;
padding-bottom:30px;
}
</style>

</head>

<body>
<div id="wrap">
<div id="wrap-content">
<!-- 头部 -->
<%@ include file="/page/top.jsp"%>

<section id="main-content" class="container eh-padding-tb-20">
<!--right-->
<article class="eh-content">
<div class="row-fluid">
<div class="span12">
<div class="row-fluid">
<div class="eh-widget-box span12 border-top-green">
<div class="eh-widget-header eh-widget-header-1">
<h4>
<i class="eh-icon-file"></i>
健康报告
</h4>
<div class="fr">
<button class="btn btn-block eh-btn-success inverse fl comment-btn" onclick="selectReportGroup()">下载</button>
</div>
</div>
</div>
</div>
<div class="row-fluid">
<div class="eh-widget-box">
<div class="eh-widget-body no-header box-height">
<div class="eh-widget-main secretary no-padding-top">
<div class="eh-space-30"></div>
<!-- 选项卡组件(菜单项nav-tabs)-->
<ul id="myTab" class="nav nav-tabs ">
<li class="active">
<a href="#base" onclick="getMealData()">膳食报告</a>
</li>
<li>
<a href="#family" class="inline" onclick="getHealthTree()">健康树</a>
</li>
<li>
<a href="#disease" onclick="getCauseReportData()">诊疗报告</a>
</li>
</ul>
<!-- 选项卡面板-->
<div class="tab-content">
<div class="tab-pane active" id="view">

</div>

</div>
</div>
</div>
</div>
</div>
</div>
</div>
</article>
</section>
</div>
</div>

<!-- 底部 -->
<%@ include file="/page/footer.jsp"%>
<div id="selectReportGroupModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="background-color:#84AC00">
<h4 class="modal-title" style="border:1rem;padding: 1rem;font-size:17px;">选择要打印的报告</h4>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="col-xs-offset-1">
<div class="form-group">
<div class="row-fluid">
<label class="radio-inline"><input type="radio" name="reportGroupRadio" value="1001"/>膳食回顾分析报告</label>
</div>
</div>
<div class="form-group">
<div class="row-fluid">
<label class="radio-inline"><input type="radio" name="reportGroupRadio" value="1002"/>医学营养诊疗报告</label>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button id="printReportButton" type="button" class="btn btn-primary" style="background-color:#84AC00;border-color: #84AC00; line-height: 2rem;" onclick="printSelectedReport()">确定</button>
<button id="closeModelButton" type="button" class="btn btn-primary" style="background-color:#84AC00;border-color: #84AC00;line-height: 2rem;" data-dismiss="modal">取消</button>
</div>
</div>
</div>
</div>
<input type="hidden" id="reportDate" value="${reportDate}"/>
<input type="hidden" id="custId" value="${custId}"/>
<input type="hidden" id="id" value="${id}"/>
<input type="hidden" id="custName" value="${customerInfo.custName}" />
</body>
</html>

/common/config.jsp 中代码如下
PublicConstant.basePath = "${common.basepath}";

//${common.basepath} 是项目的根目录

出现的问题是 PublicConstant.basePath 的值只在页面加载的时候有值,点击onclick事件调用时PublicConstant.basePath的值就为空。将全部的PublicConstant.basePath替换为${common.basepath}就没问题了。求大神指点
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jsp 项目路径
相关文章推荐