my dog learned polymorphism
The moose likes JSP and the fly likes calling a scriptlet on submit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "calling a scriptlet on submit" Watch "calling a scriptlet on submit" New topic

calling a scriptlet on submit

dhriti joshi
Ranch Hand

Joined: Aug 13, 2002
Posts: 82
i want that when i submit the form a part of scriptlet on same jsp should run,
how do i do it.
please help.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63540

You don't.
JSP runs on the server to format the HTML page to send to the browser. Once on the browser, you can manipulate the page using Javascript. The JSP's work is long done and the only way you can get back to the server is to submit a new request.

[Asking smart questions] [About Bear] [Books by Bear]
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Why do you want to do that Dhriti? What do you want to accomplish by doing that? Can you post this information? That will enable us to give you a better approach on how to do it. It is generally considered not a good practice to embed java scriptlets in JSPs. There are always exceptions to rules; however if you can get away from embedding scriptles in JSPs you should.

Ever Existing, Ever Conscious, Ever-new Bliss
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63540

It's really not an issue of whether there are scriplets in the JSP page or not. The point is, any scriplets are run on the server long before the page is sent to the browser, and there is no way to "trigger" one of the scriplets on a client-side event like onsubmit.
Anil Kumar

Joined: Jan 17, 2004
Posts: 11
you can submit to the same jsp with a value assigned to a hidden form field. Depending upon the value of this hidden field you can get the neccesary scriptlet to be executed on the server. I prefer this way when the same gui is to be maintained through a sequence of dynamic selections like country>state etc.
It is sorta covered in the JavaRanch Style Guide.
subject: calling a scriptlet on submit
It's not a secret anymore!