0

I have a JSP page containing a data Table. I want to pass the content of the first column of a row ,when clicked, to another jsp page. I am working with spring framework. I have tried to achieve it,but with some problem. The problem is : When I am retrieving the parameter in another jsp page, i get some content,but the contents after the first blank space are skipped.

Here is the code I have tried: source jsp page:

$(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;
});
});     

the controller:

@RequestMapping(value="/test/integrate", method = RequestMethod.GET)
public String pass_parameter_by_type(ModelMap model,HttpServletRequest request,HttpServletResponse response) {

return "destination";
}

the destination jsp page:

<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>

if the value passed is "cool guy", then in url it shows test/integrate?group=cool guy. but in alert it shows only "cool". Please help.

4 Answers 4

1

Here is what I have done to get the results: I replaced blank with an underscore("_").

pass_on=aData[0];
var res=pass_on.replace(/ /g,"_");
window.location.href = "/test/integrate"+"?"+"group="+res;

No more changes. Rest of it works fine. I still don't know why %20 didn't work.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to pass cool%20guy.

URLs don't understand special chars

http://www.w3schools.com/tags/ref_urlencode.asp

1 Comment

I replaced blank spaces with %20 but no change.
0

Encode your text. For javascript

escape(...)

For java, use:

URLEncoder.encode( ,encoding)

Comments

0

In your controller do like this:

@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";
}

In your other JSP do like this:

<body>
<input type="button" id="sub_but">
<input type="hidden" value="${group}" id="group_parameter">
$("#sub_but").click(function(){
alert($("#group_parameter").val());             
        });
</body>

I hope it should solve your problem. :)

2 Comments

@ Shailesh Saxena: it throws error in controller: requestParam cannot be resolved to a type - The attribute value is undefined for the annotation type
Oops! My Mistake only! I edited my answer and kept the right code there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.