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">
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to find missing packages when using Netbeans IDE 8.1 ? 19 54
spring JDBC Template example error 26 244
java operators 3 116
web application structure 18 77
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

803 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