Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing a primitive in query string  RSS feed

 
Zeko Mbumwae
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How can I pass a double/int in a query string? e.g say amount and period are primitive variables ==> response.sendRedirect(loanupdate.jsp?pay=amount&numMths=period)
How do I get to pass the primitive values.
Thanks
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zeko Mbumwae wrote:Hi,
How can I pass a double/int in a query string? e.g say amount and period are primitive variables ==> response.sendRedirect(loanupdate.jsp?pay=amount&numMths=period)
Thanks




Or use StringBuilder...
 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The parameters passed through the URL are always strings, doesn't matter what do you have there, you have to cast them later, in your exapmle you have to pass:

loanupdate.jsp?pay=1000&numMths=5

and then cast it in the servlet, you can do something like this: int numMths = Integer.getInteger(request.getParameter("numMths"));
Take care that you have to be sure that what you are passing is a integer or a ClassCastException will be thrown.
 
Zeko Mbumwae
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Albareto McKenzie wrote:The parameters passed through the URL are always strings, doesn't matter what do you have there, you have to cast them later, in your exapmle you have to pass:

loanupdate.jsp?pay=1000&numMths=5

and then cast it in the servlet, you can do something like this: int numMths = Integer.getInteger(request.getParameter("numMths"));
Take care that you have to be sure that what you are passing is a integer or a ClassCastException will be thrown.


Thanks for the reply.What I want is to have the variable pay and numThs populated from methods(say loanupdate.jsp?pay=client.getPay()&numMths=client.getPeriod() not hard coded like in ===> loanupdate.jsp?pay=1000&numMths=5
I see in href its possible.I want it like response.sendRedirect( loanupdate.jsp?pay=client.getPay()&numMths=client.getPeriod());
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So just build the query string using ordinary Java code:
 
Zeko Mbumwae
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Okay. So just build the query string using ordinary Java code:


Thanks it works.Sorry for the silly question .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!