Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Call javascript function in servlet or jquery modal box how to display in servlet  RSS feed

 
Dinesh Ravi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't need ordinary javascript alert box. so i was use the jquery modal alert box for different action like success, error etc.
but i have problem to call the alert box within servlet how to call any one tell me.



out.println("<link href=\"css/jquery.modal.css\" type=\"text/css\" rel=\"stylesheet\" />");
out.println("<script type=\"text/javascript\" src=\"js/jquery-latest.min.js\">");
out.println("<script type=\"text/javascript\" src=\"js/jquery.modal.min.js\">");
out.println("<script type=\"text/javascript\" src=\"js/jscript.js\">");
out.println("<script type=\"text/javascript\" src=\"js/success.js\">");
out.println("<script type=\"text/javascript\">");
response.getOutputStream().println("success();");
out.println("</script>");

how to call the modal function in the js file?

otherwise how to show the modal alert box?

please tell me.
 
Dave Tolls
Ranch Hand
Posts: 2507
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet codes runs on the server.

The Javascript code runs on the client/browser.

The servlet does not call the Javascript.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As pointed out, the servlet only creates the HTML and JavaScript code to send to the client. The JavaScript executes long after the servlet has finished running.

So you're doing it backwards. You should be designing what your HTML and JavaScript need to be. And then write the servlet to create that HTML.

Why are you not using JSP to create the markup? Generating HTML in a servlet is rather a poor practice.
 
Dinesh Ravi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was used jsp page if form submit call the servlet page. the servlet page can insert code into database. if added successfully show alert message generally javascript alert was worked but i need to show different alert box success, error. what can i do?
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use Ajax calls from your JavaScript. jQuery will make it easier. The $.ajax() function has callbacks that you can use to determine the result.

And does it have to be an alert box? I usually use a hidden div to display success-failure messages. Display the message and fade it out after a few seconds. That way the user gets the status information but they don't have to click anything to continue.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that alerts awe an awful way to show messages. There are many jQuery plugins to show messages. Search for terms like "query growl" or ":query gritter".
 
Dinesh Ravi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. if you give example code to implement the alert box or call the Ajax function.


i was used the jQuery Modal 1.2 alert box.

the main function for call the alert box is modal


this jquery alert box was using
http://creativedream.net/plugins/jquery.modal/

give me suggestion.

thanks
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are NotACodeMill (<-- link), we are a learning site that encourages everyone to struggle through the problem on their own and we'll help with specific issues. But since you seem lost on how to use Ajax, I'm going to give a little push in the right direction. Give it your best shot and then post your code here and explain the issues you are having.
You need an even handler to fire off the Ajax request. That's typically done with a button that has a type="button", not a type="submit".

The above is going to enclose your Ajax function:

That's a rough idea, but this along with the documentation on the jQuery site should get you started.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!