Reputation: 11649
I am required to pass an arithmetic operation like 2+8
to a restful back-end and receive the result. I know that a simple operation can be handled in frontend using javascript, but i just want to follow the requirement.
I send the operations with the following uri:
http://localhost:8080/?question=2+5
and in the back-end i have:
@RequestMapping("/")
public String getAnswer(@RequestParam("question") String question){
System.out.println("recieved question is: "+question);
return botService.Evaluator(question);
}
When i print the question
it is like 2 3
so there is no operation there.
And the component complains with:
javax.script.ScriptException: <eval>:1:2 Expected ; but found 5
2 5
^ in <eval> at line number 1 at column number 2
So, why the +
is missing?
and how can i fix it?
Upvotes: 0
Views: 445
Reputation: 608
You need URL Encoding here. for more details regarding URL Encoding please have a look in below link.
Upvotes: 0
Reputation: 73558
Use the URLEncoder
class to make sure any special characters are encoded safely for transport.
Upvotes: 2
Reputation: 3667
You need to encode the '+' symbol as the server will just translate it as a space.
Send...
http://localhost:8080/?question=2%2B5
Upvotes: 0