javascript in servet

Hi,
Can i use javaScript inside the doGet...:
e.g:
....doGet(request, response ).....{
....
if ( "".equals(eventTitle) || "".equals(eventDate) ) {
        out.println("<b><i>Please enter event title and date.</i></b>");<===== USE SOME 'alert( )' HERE
    } else {
        createAndStoreEvent(eventTitle, dateFormatter.parse(eventDate));
        out.println("<b><i>Added event.</i></b>");
    }

}
komlaaaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bloodredsunCommented:
Yes you can.

You need to put it in exactly as you would your html as the javascript gets executed by the browser not the server. The only real issue is remembering to esacpe the quote marks with a slash.

e.g.
....doGet(request, response ).....{
....
if ( "".equals(eventTitle) || "".equals(eventDate) ) {
        out.println("<script type=\"text/javascript\">");
        out.println("alert(\"Please enter event title and date.\");");
        out.println("</script>");
    } else {
        createAndStoreEvent(eventTitle, dateFormatter.parse(eventDate));
        out.println("<b><i>Added event.</i></b>");
    }
}

But if you are using it like this it would make more sense for you to write the content out to the page rather than putting it in an alert.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
komlaaaAuthor Commented:
:), very neat. Let me give a try
bloodredsunCommented:
no worries koom and have a happy new year :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.