chaitu chaitu
asked on
error while using ternary operator in jsp
whats wrong with this
<input type="text" searchField="true" class='text' maxlength="2" size="2" value='<%=out.println(requ est.getPar ameter("co untryId") != null ? request.getParameter("coun tryId") : "" )%>' name="countryId"
i am getting this error
Incompatible type for method. Can't convert void to java.lang.Object. out.print(out.println(requ est.getPar ameter("co untryId") != null ? request.getParameter("coun tryId") : "" ))
<input type="text" searchField="true" class='text' maxlength="2" size="2" value='<%=out.println(requ
i am getting this error
Incompatible type for method. Can't convert void to java.lang.Object. out.print(out.println(requ
FYI
<%=expression%>
expression is a combination of variable and operation that final return only one value.
You use this
out.println(request.getPar ameter("co untryId") != null ? request.getParameter("coun tryId") : "" )
It's not expression since it return void. jsp expression cannot accept method that return void.
If you really want to use expression instead of scriptlet, I think it should be
<%=request.getParameter("c ountryId") != null ? request.getParameter("coun tryId") : ""%>
<%=expression%>
expression is a combination of variable and operation that final return only one value.
You use this
out.println(request.getPar
It's not expression since it return void. jsp expression cannot accept method that return void.
If you really want to use expression instead of scriptlet, I think it should be
<%=request.getParameter("c
ok...for your reference,
whatever you give inside the <%= and %> is considered to be a out.print
i.e. <%=yourContent%> itsellf refers to out.print(yourContent);
So, this is the way normally developers use:
<input type="text" searchField="true" class='text' maxlength="10" size="10" value='<%=request.getParam eter("coun tryName") != null ? request.getParameter("coun tryName") : ""%>' name="countryName">
whatever you give inside the <%= and %> is considered to be a out.print
i.e. <%=yourContent%> itsellf refers to out.print(yourContent);
So, this is the way normally developers use:
<input type="text" searchField="true" class='text' maxlength="10" size="10" value='<%=request.getParam
haaa....didnt noticed your comment sampol..
For more clarification about jsp,
when you create jsp file and deploy to server. the server will translate jsp to servlet line by line.
<%="abc"%>
will be convert to
out.println("abc");
when you create jsp file and deploy to server. the server will translate jsp to servlet line by line.
<%="abc"%>
will be convert to
out.println("abc");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
<input type="text" searchField="true" class='text' maxlength="10" size="10" value='<%out.println(reque