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">
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now