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

[579 byte] By [vivek.shankara] at [2007-10-2 4:38:39]
# 1

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

vivek.shankara at 2007-7-16 0:11:46 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

>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>

evnafetsa at 2007-7-16 0:11:46 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Thanks a lot !! that looks proffesional :-) i am just playing around with a legacy code...so im not sure if i can use JSTL in it......can i?thanksvivek
vivek.shankara at 2007-7-16 0:11:46 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Scope of String object is limited as local. It will not accessible outside of else block.
dfsfsda at 2007-7-16 0:11:46 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...