Salman Salman - 11 months ago 54
Java Question

pass arithmetic operation with http get request

I am required to pass an arithmetic operation like

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:


and in the back-end i have:

public String getAnswer(@RequestParam("question") String question){

System.out.println("recieved question is: "+question);
return botService.Evaluator(question);


When i print the
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?

Answer Source

Use the URLEncoder class to make sure any special characters are encoded safely for transport.