Link to home
Start Free TrialLog in
Avatar of r_muthu
r_muthu

asked on

convert String to int in JavaServer Pages

How can I convert String to int in JavaServer PagesTM?

I'm having a problem converting String to int on JavaServer Pages. This is the code I used:

 

 <%
String ss= request.getParameter("prior");  
int ii = Integer.parseInt(ss);
%>
ii=<%=ii%>

The output i got is
 
 A Servlet Exception Has Occurred
java.lang.NumberFormatException: 15
at java.lang.Integer.parseInt(Integer.java:414)
     at java.lang.Integer.parseInt(Integer.java:454)


the value for prior=15




Thanks,
Muthu



Avatar of urxlnc
urxlnc

I assume you have imported the necessary files.
<%@ page import="java.jang.*, java.io.*" %>

<%
String ss= request.getParameter("prior");  
int ii = Integer.parseInt(ss);
%>
ii=<%= ii %>

The space is important in <%= ii %>.
Try now!!!
ASKER CERTIFIED SOLUTION
Avatar of urxlnc
urxlnc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial