Question

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...

Était-ce utile?

La solution 2

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"));%>

Autres conseils

You need to use parseInt

<% int r=Integer.parseInt(request.getParameter("param"));%>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top