I'm trying to auto-populate a drop down list based on a request parameter. I'm fairly new to JSP so forgive me for the simple question.
The following works fine and displays the alert correctly:
alert('<%=request.getParameter("lang") %>');
So I know what I am trying to do is easy enough. But when I add this same logic in with my select statement using:
<option <c:if test="${request.getParameter(\"lang\")=='En'}"> selected="selected" </c:if> value="<c:out value="${english}"/>">English</option>
I get an exception saying "The function getParameter must be used with a prefix when a default namespace is not specified".
I'm a little confused as to why this doesn't work here...
Thanks in advance
request.getParameter()
will not resolved by EL. Request parameter can be accessed using implicit variable param
. i.e, ${param.lang}
Change this
<option <c:if test="${request.getParameter(\"lang\")=='En'}"> selected="selected" </c:if> value="<c:out value="${english}"/>">English</option>
to
<option <c:if test="${param.lang == 'En'}"> selected="selected" </c:if> value="${english}">English</option>
another way :
<option <c:if test='${param[lang] == "En"}'> selected="selected" </c:if>
value="${english}">
English
</option>
Make sure you have added c-taglibs URI on top of the JSP.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With