how to print a string variable in jsp?

i have to printan error msg in a jsp:<% String meser = (String)request.getAttribute("msg_error"); if (meser!=null) out.print(meser);%> but it doesn't print anything...how it can be done correctly?i know 4 sure that meser isn't null...
[277 byte] By [puiutza] at [2007-10-2 13:00:46]
# 1
Hicheck out.println("COnditional"+(meser!=null));
skpmcaa at 2007-7-13 10:20:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
nopethe first time when jsp runs it returns a null meser, but in excuting the servlet it can return an msg_err, so in this case i need to print the meserso your solution doesn't work :)
puiutza at 2007-7-13 10:20:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
hi instead of using scirptlet like<% String meser = (String)request.getAttribute("msg_error");if (meser!=null) out.print(meser);%> u can use<c:out value="${msg_error}"/>
SuryaPrakash_Indiaa at 2007-7-13 10:20:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
no..thanks but it didn't worked...any other ideas?
puiutza at 2007-7-13 10:20:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
for elucidate the question, this is the servlet:String ms ="Insert failed!!";request.setAttribute("msg_error",ms);RequestDispatcher rd = request.getRequestDispatcher("/insertNewTimereg.jsp");rd.forward(request, response);
puiutza at 2007-7-13 10:20:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

For debugging purposes, do something like

The value of the error message is "<%= meser %>"

View source on the generated HTML. Is the error message being printed into that? Is it maybe enclosed in tags so it wouldn't be printed to the page?

Personally I prefer the JSTL approach with the c:out tag.

evnafetsa at 2007-7-13 10:20:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
if i do <%=meser%> the servlet generated is:String meser =request.getAttribute("msg_error").toString();if (meser.length()!=0) out.print(meser);but also it doesn't working :( help me please
puiutza at 2007-7-13 10:20:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

>For debugging purposes, do something like

>The value of the error message is "<%= meser %>"

I didn't say put this into an if statement, I said put it on the page for debugging purposes.

Print that value on the page so you see its value regardless of whether it is null or not. Also you will see if it prints anything between the quotes.

I am questioning your base assumption that the value of the attribute msg_error has a non-null, non-empty value.

This will prove what the value is.

It could be that the value of meser is empty string - ie "", which currently would be indistinguishable from null.

When debugging you constantly have to question your base assumptions. So what is the actual value of this attribute? Why is it this value? Where does it get set?

Good luck,

evnafets

evnafetsa at 2007-7-13 10:20:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
yep, without if <% String meser = (String)request.getAttribute("mesajer");%><%=meser%>it works like this: first time it prints : null then, if an error occured, it prints the error message...but why it works like this? what's wrong with that
puiutza at 2007-7-13 10:20:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
finally, i found i way to print it !! :<% String meser = (String)request.getAttribute("mesajer");if(meser==null) { }else {%><%=meser%><%}%>
puiutza at 2007-7-13 10:20:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...