开发者

Illogical jsp error

I want to dispaly a result parameter which return from servlet to jsp after an event happen. so when i add new user for example a result parameter returns with value that the user has been added successfully , and i want to display the result in jsp page. i make like this in jsp page

<%String result = String.valueOf(request.getAttribute("result"));%>
 <%if (result != null){%>
 <%= result%>
<%}%&开发者_开发问答gt;

THE PROBLEM is that every time i open the page for the first time result prints as null to the browser even i write if not null print result value, where is the problem ? can someone help/


String.valueOf(..) returns "null" (a String with length 4) if the argument is null. So your quick solution would be not to use String.valueOf(..) at all.

However, it is not advisable to use scriptlets and java code like that in your JSPs. Use JSTL and EL instead. Your code would look like this:

<c:if test="${result != null}">
    ${result}
</c:if>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜