problem with jsp code
Hi,
Is there anything wrong in this piece of code?
<%if ( request.getParameter("yy").equals("Other")){ String yy = request.getParameter("Other"); %>
<%}else{ String yy = request.getParameter("yy"); %>
<%} %>
<%= yy %>
Thanks
vivek
Hi,
also cud you tell me what is wrong with this piece of code...
<jsp:forward page="insertADC.jsp">
<% if (request.getParameter("yy").equals("Other") ) { %>
<jsp:param name="yy" value="<%= request.getParameter(\"Other\")%>
<% } else { %>
<jsp:param name="yy" value="<%= request.getParameter(\"yy\")%>
<% } %>
</jsp:forward>
Thanks
vivek
>Is there anything wrong in this piece of code?
Apart from the ugly mix of scriptlet code with jsp?
With the first one, the scope of your string is limited to the curly braces.
It is no longer available when you try printing it with a scriptlet expression.
Solution: declare the String "yy" outside of the curly braces.
<%
String yy = null;
if (request.getParameter"yy".....{
yy = request.getParameter("other");
}
...
<%= yy %>
More preferable I think would be using JSTL, or a better scriptlet expression.
How about
<%= request.getParameter("yy").equals("Other") ? request.getParameter("Other") : request.getParameter("yy") %>
or using JSTL
<c:choose>
<c:when test="${param.yy == 'Other'}">
<c:out value="${param.Other}"/>
</c:when>
<c:otherwise>
<c:out value="${param.yy}"/>
</c:otherwise>
</c:choose>