yaylitzis
yaylitzis

Reputation: 5534

get a value from url - jsp

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

Upvotes: 1

Views: 2055

Answers (2)

PSR
PSR

Reputation: 40318

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

Upvotes: 0

Mark Nenadov
Mark Nenadov

Reputation: 6907

You need to use parseInt

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

Upvotes: 1

Related Questions