0

When a variable is passed from java layer to JSP, if the string starts with 0(Zero), it is automatically converts it to Octal otherwise it is working fine.

Inside the Java code I am sending one distID

response.sendRedirect("ExpTool.jsp?test=1&&distID="+distID);

And inside the JSP code I am receiving the distID as

String distID=(String)request.getParameter("distID");

Its working fine except the scenario when distID is like '004352' i.e., when it starts with '0(zero)'. Whenever it starts with '0', it is automatically converted into its Octal Equivalent. I need solution for the scenario when distID starts with '0'.

Sam
  • 97
  • 1
  • 14
  • 3
    And what is the question? And where does JavaScript enter the question? Please visit the [help] to see how and what to ask here. If your question is JavaScript related, you need to use radix 10 - `parseInt("09",10)` to get integers - same for 08 – mplungjan Nov 23 '15 at 12:23
  • 1
    If the value is a number, why are you passing it from Java as a String? – Andreas Nov 23 '15 at 12:30
  • You have not provided a single line of code that is relevant to your question. Please amend your question with code snippet so that we can help you better. – ha9u63a7 Nov 23 '15 at 12:30
  • Possible duplicate of [How do I work around JavaScript's parseInt octal behavior?](http://stackoverflow.com/questions/850341/how-do-i-work-around-javascripts-parseint-octal-behavior) – ha9u63a7 Nov 23 '15 at 12:31
  • yea javascript is not there, i got confused. Its in normal JSP page, can you help on that? And sorry if my question is not clear, I want that the variable that I am passing through java layer should not be converted to Octal even if it is starting from 0(zero). – Sam Nov 23 '15 at 12:32
  • Please post your code. It's java, rather than javascript, correct? – vikingsteve Nov 23 '15 at 12:44
  • Possible duplicate of [Why is 08 not a valid integer literal in Java?](http://stackoverflow.com/questions/7218760/why-is-08-not-a-valid-integer-literal-in-java) – mplungjan Nov 23 '15 at 12:47

2 Answers2

0

Evidently - you want a number - for some reason there are preceding zeroes

Call somepage.jsp?notsixteen=020. As a String request parameter in java is no problem, probably the problem if for ${...}:

Expression Language:

${2 + Integer.parseInt(param.notsixteen, 10)}
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
0

Please verify this:

request.getParameter("distID");
                      ^^^^^^

it should be "dist" not the "distID" as you have written. As your request parameter name is "dist";

Ashish Ani
  • 324
  • 1
  • 7