我有一个JSP页面,它加载另一个JSP页面的内容,工作非常好。问题是我想把request.getParameter("cfgname")
传递给这个内容页面,这样当它被加载到主JSP中时,内容就完成了。(当前代码显示我使用null
代替request.getParameter
这是我的主JSP页面,它得到cfgid=41&cfgname=Abhishek&cfgdesc=test1&cfgtype=Development&filepath=files%2Fcsmclientbuckeye.xml
<title>Testing</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.get("content.jsp", addContent);
function addContent(data)
{
$("#content").html(data);
}
});
</script>
</head>
<body>
<div id="content"></div>
</body>
Content.jsp页面
<table class="csm-table" width="100%" cellspacing="0" cellpadding="4" border="0">
<tbody>
<tr>
<th width="25%">Configuration Name</th>
<td width="25%"><span id="cname"><%= request.getParameter("cfgname") %></span></td>
<th width="25%">Host Name</th>
<td width="25%"><span id="chostname">{hostname}</span></td>
</tr>
<tr> </tr>
<tr>
<th>Configuration Description</th>
<td><span id="cdesc"><%= request.getParameter("cfgdesc") %></span></td>
<th width="25%">Os Name</th>
<td width="25%"><span id="cosname">{osname}</span></td>
</tr>
<tr>
<th>Configuration Type</th>
<td><span id="ctype"><%= request.getParameter("cfgtype") %></span></td>
<th>Product Name</th>
<td><span id="cproductname"></span></td>
</tr>
<tr>
<th>Last Updated Time</th>
<td><span id="clastupdatetime"></span></td>
<th>Configuration File Name</th>
<td><span id="cfilename"><%= request.getParameter("filepath") %></span></td>
</tr>
</tbody>
</table>
你(Kees和Mick)的回答对我都有帮助我做了$.get("content.jsp?cfgname=<%= request.getParameter("cfgname") %>", addContent);
,解决了我的问题。谢谢各位
从您的代码示例中可以看出,您正在调用不带参数的content.jsp:
$.get("content.jsp", addContent);
你需要这样称呼它:
$.get("content.jsp?cfgid=41&cfgname=Abhishek&cfgdesc=test1&cfgtype=Development&filepath=files%2Fcsmclientbuckeye.xml", addContent);
从本质上讲,AJAX调用不会立即访问您首先加载的页面的URL参数,因此,如果您需要将它们传递给另一个HTTP请求(AJAX调用就是这样),那么您需要遵循其他发布者的建议来构建查询字符串。