error while using ternary operator in jsp

Posted on 2004-09-09
Last Modified: 2008-02-01
whats wrong with this

<input type="text" searchField="true" class='text' maxlength="2"  size="2"  value='<%=out.println(request.getParameter("countryId") != null ? request.getParameter("countryId") : "" )%>'         name="countryId"

i am getting this error

Incompatible type for method. Can't convert void to java.lang.Object. out.print(out.println(request.getParameter("countryId") != null ? request.getParameter("countryId") : "" ))

Question by:chaitu chaitu
LVL 20

Author Comment

by:chaitu chaitu
ID: 12015890
i solved the problem like this

<input type="text" searchField="true" class='text' maxlength="10"  size="10"  value='<%out.println(request.getParameter("countryName") != null ? request.getParameter("countryName") : "" );%>'   name="countryName" >
LVL 11

Expert Comment

ID: 12017903

expression is a combination of variable and operation that final return only one value.

You use this
out.println(request.getParameter("countryId") != null ? request.getParameter("countryId") : "" )
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("countryId") != null ? request.getParameter("countryId") : ""%>
LVL 32

Expert Comment

ID: 12018005
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.getParameter("countryName") != null ? request.getParameter("countryName") : ""%>'  name="countryName">
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 32

Expert Comment

ID: 12018038
haaa....didnt noticed your comment sampol..
LVL 11

Expert Comment

ID: 12023339
For more clarification about jsp,

when you create jsp file and deploy to server. the server will translate jsp to servlet line by line.


will be convert to


Accepted Solution

modulo earned 0 total points
ID: 12531593
PAQed, with points refunded (50)

Community Support Moderator

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audi…
Read about why it is more lucrative for an IT company to participate in government projects.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question