![](/img/trans.png)
[英]How to send parameter by controller (Spring) to an Angularjs module for display in jsp?
[英]How to send parameter to a jsp page using querystring via a controller in spring framework?
我有一個包含數據表的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;
});
});
控制器:
@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。 但在警報中僅顯示“酷”。 請幫忙。
這是我為獲得結果所做的工作:我用下划線(“ _”)替換了blank。
pass_on=aData[0];
var res=pass_on.replace(/ /g,"_");
window.location.href = "/test/integrate"+"?"+"group="+res;
沒有更多的變化。 其余的工作正常。 我仍然不知道為什么%20無法正常工作。
在您的控制器中執行以下操作:
@RequestMapping(value="/test/integrate", method = RequestMethod.GET)
public String pass_parameter_by_type(ModelMap model,@RequestParam String group,HttpServletRequest request,HttpServletResponse response) {
model.addAttribute("group",group);
return "destination";
}
在您的其他JSP中執行以下操作:
<body>
<input type="button" id="sub_but">
<input type="hidden" value="${group}" id="group_parameter">
$("#sub_but").click(function(){
alert($("#group_parameter").val());
});
</body>
希望它能解決您的問題。 :)
對您的文本進行編碼。 對於javascript
escape(...)
對於Java,請使用:
URLEncoder.encode( ,encoding)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.