1

hello! I have this url www.someurl.jsp?param=1 and i want to store the 1 into a variable

i wrote this

<% int r=request.getParameter("param");%>

and i have an error "incompatible types ,required:int, found:String" i wrote then this

<% int r= (int) request.getParameter("param");%>

but it doesnt work also...

yaylitzis
  • 5,354
  • 17
  • 62
  • 107

2 Answers2

1

You need to use parseInt

<% int r=Integer.parseInt(request.getParameter("param"));%>
Mark Nenadov
  • 6,421
  • 5
  • 24
  • 32
0

request.getParameter("param") will return String.So you need to convert it to int.For that you need to do typecasting

like

<% int r=Integer.parseInt(request.getParameter("param"));%>
PSR
  • 39,804
  • 41
  • 111
  • 151