我有一个包含数据表的 JSP 页面。我想在单击时将一行第一列的内容传递到另一个jsp页面。我正在使用 spring 框架。我试图实现它,但有一些问题。问题是:当我在另一个jsp页面中检索参数时,我得到了一些内容,但第一个空格之后的内容被跳过。
这是我尝试过的代码: 源jsp页面:
$(document).ready(function(){
$("#mytable tbody tr").click(function(){
var aPos = $('#mytable').dataTable().fnGetPosition(this);
var aData = $('#mytable').dataTable().fnGetData(aPos);
pass_on=aData[0];
window.location.href = "/test/integrate"+"?"+"group="+pass_on;
});
});
Controller :
@RequestMapping(value="/test/integrate", method = RequestMethod.GET)
public String pass_parameter_by_type(ModelMap model,HttpServletRequest request,HttpServletResponse response) {
return "destination";
}
目标jsp页面:
<body>
<input type="button" id="sub_but">
<input type="hidden" value=<%=request.getParameter("group") %> id="group_parameter">
$("#sub_but").click(function(){
alert($("#group_parameter").val());
});
</body>
如果传递的值为“cool Guy”,则在 url 中显示 test/integrate?group=cool Guy。 但在警报中它只显示“酷”。 请帮忙。
最佳答案
这是我为获得结果所做的事情: 我用下划线(“_”)替换了空白。
pass_on=aData[0];
var res=pass_on.replace(/ /g,"_");
window.location.href = "/test/integrate"+"?"+"group="+res;
没有更多的变化。其余部分工作正常。 我仍然不知道为什么 %20 不起作用。
关于java - 如何通过Spring框架中的 Controller 使用查询字符串将参数发送到jsp页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24303141/