Reputation: 5
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
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