kamal8878
kamal8878

Reputation: 5

How to resolve space from jsp to servlet?

While passing string with space (ex: Item 1) from jsp to servlet, the result in servlet from request is only string before the space (ex: Item). How to resolve this?

JSP:
(Fetching the values from .txt file and populate the values in jsp)
s1[i] is: Item 1

<input type="hidden" name="ItemsFromJsp" value=<%=sItems%>> <%=s1[i]%>

Servelt:

String[] sItemsFromJsp = request.getParameterValues("ItemsFromJsp");

OutPut:

sItemsFromJsp---------- Item

Output Should be: Item 1

Note: If Sending Like Item1 as input, the O/P is Item1

Upvotes: 0

Views: 983

Answers (1)

Joop Eggen
Joop Eggen

Reputation: 109613

Use quotes: :)

value="<%=sItems%>"> 

P.S. You are aware of getParameter in the case of one single parameter?

String sItemsFromJsp = request.getParameter("ItemsFromJsp");

or

String[] sItemsFromJsp = request.getParameter("ItemsFromJsp").split(",\\s+");

if you have a comma separated item list.

Upvotes: 1

Related Questions