Javascript中的日志
在Jsp文件中,我想在系统日志中打印一些变量值。我的警报正在工作,这也在工作:Javascript中的日志,javascript,logging,Javascript,Logging,在Jsp文件中,我想在系统日志中打印一些变量值。我的警报正在工作,这也在工作: 但是, 没有任何结果 请给我一些见解。 我已经花了这么多时间,但没有结果 <script> window.onload = function() { var actionURL; var theForm = document.forms['reportForm']; <% // Incase of BROS
但是,
没有任何结果
请给我一些见解。
我已经花了这么多时间,但没有结果
<script>
window.onload = function()
{
var actionURL;
var theForm = document.forms['reportForm'];
<%
// Incase of BROS do not post baseURl as parameter it will be set in Servlet
// Incase of Non-Bros the url of the browser is treated as baseURL.
String redirUrl=(String)reportParams.get("redir");
redirUrl=redirUrl.toUpperCase();
if(redirUrl.startsWith("HTTP://") || redirUrl.startsWith("HTTPS://"))
{
%>
actionURL="<%=reportParams.get("redir")%>";
<%
}
else
{
%>
var docURL = document.URL;
var urlStartingFromContext="<%=request.getContextPath()%>/webclient/common/openreport.jsp";
var n =docURL.indexOf(urlStartingFromContext);
var baseUrl=docURL.substring(0,n);
if(baseUrl)
{
var input = document.createElement('input');
input.type = 'hidden';
input.name = 'baseUrl';
input.value = baseUrl;
theForm.appendChild(input);
actionURL=baseUrl+"<%=reportParams.get("redir")%>";
}
else
actionURL="<%=reportParams.get("redir")%>";
<%
}
%>
theForm.action =actionURL;
reportForm.submit();
};
</script>
window.onload=函数()
{
var-actionURL;
var theForm=document.forms['reportForm'];
actionURL=“”;
var docURL=document.URL;
var urlStartingFromContext=“/webclient/common/openreport.jsp”;
var n=docURL.indexOf(urlStartingFromContext);
var baseUrl=docURL.substring(0,n);
if(baseUrl)
{
var input=document.createElement('input');
input.type='hidden';
input.name='baseUrl';
input.value=baseUrl;
appendChild格式(输入);
actionURL=baseUrl+“”;
}
其他的
actionURL=“”;
form.action=actionURL;
reportForm.submit();
};
提前感谢您在浏览器中运行JavaScript,您的JSP没有变量值。JSP只能将Java变量转换为字符串,但JavaScript只是其中的纯文本。我没有JSP方面的经验,但看起来您正在呈现HTML/JS模板,并在
括号之间插入值。这意味着您可以打印来自服务器的值,但不能打印来自服务器的值。渲染代码并替换值时,文件将发送到浏览器。因此,您无法将Javascript中定义的值读回服务器。它不是双向数据流
您可以打印到HTML和JS中,但不是从JS到ASP或C#,或者您使用的服务器端语言是什么。在getit中使用单引号。它可能是空的,所以请尝试
@AZ_u。我尝试了在警报中提供适当值的it操作URL,但这里给出了空值。这让我很生气,意味着如果您需要记录一个值,我无法在系统日志中打印该值由JavaScript生成,您必须将其发送到后端。
<script>
window.onload = function()
{
var actionURL;
var theForm = document.forms['reportForm'];
<%
// Incase of BROS do not post baseURl as parameter it will be set in Servlet
// Incase of Non-Bros the url of the browser is treated as baseURL.
String redirUrl=(String)reportParams.get("redir");
redirUrl=redirUrl.toUpperCase();
if(redirUrl.startsWith("HTTP://") || redirUrl.startsWith("HTTPS://"))
{
%>
actionURL="<%=reportParams.get("redir")%>";
<%
}
else
{
%>
var docURL = document.URL;
var urlStartingFromContext="<%=request.getContextPath()%>/webclient/common/openreport.jsp";
var n =docURL.indexOf(urlStartingFromContext);
var baseUrl=docURL.substring(0,n);
if(baseUrl)
{
var input = document.createElement('input');
input.type = 'hidden';
input.name = 'baseUrl';
input.value = baseUrl;
theForm.appendChild(input);
actionURL=baseUrl+"<%=reportParams.get("redir")%>";
}
else
actionURL="<%=reportParams.get("redir")%>";
<%
}
%>
theForm.action =actionURL;
reportForm.submit();
};
</script>