• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code written in scriptlet of JSP

 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
I know that the scriptlet written in a JSP finally goes into the service method
but I want to know how we can call that method from a HTML form


like
when we write in HTML < form = "form1" action = "SampleServlet" method = "GET/POST" > for calling a servlet

what do we write for JSP?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2345
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prasad,

I am not sure whether I am getting your question, but do you want to know how you can call the service method from a JSP?

Regards,
Frits
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can be a JSP or HTML also

I want to know
how we can call the JSP service method from the FORM tag of HTML
like to write METHOD = "GET" or METHOD = "POST" for servlets
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2345
90
Android Chrome Eclipse IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know how we can call the JSP service method from the FORM tag of HTML

You can't call it directly.

(the http request is send from the client to the server and handled by the public service() method of the HttpServlet class, which dispatches the request to the protected service() method which dispatches the request to the doGet(), doPost() (also known as the doXXX ) methods defined in this class)

Regards,
Frits
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so what should I write in the FORM tag?

method = "POST"
of
method = "GET"

I want to submit data so I need to use POST method, but if the code written in scriptlet goes into service method, what is the use of writing POST in FORM tag?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2345
90
Android Chrome Eclipse IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still not getting you...

the "post" method in the HTML-form just corresponds with the doPost() method of your Servlet (a JSP is also turned into a Servlet)

can you post your html or jsp you want to create?

Regards,
Frits
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frits Walraven wrote:

the "post" method in the HTML-form just corresponds with the doPost() method of your Servlet (a JSP is also turned into a Servlet)




sir,
I know that JSP is turned into servlet

now for a HTML form to call a JSP on method POST, where should I write code in JSP?
if I write the code in scriptlet, then while converting to servlete, the code goes in service method, so how can I call the doPost method of JSP that is converted to servlet?


I have not written the code yet but will do it tomorrow morning

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so how can I call the doPost method of JSP that is converted to servlet?

By using POST as the method of the HTML form.

Using a JSP for processing is bad style, though, and you should not do that at all. Instead, write a servlet.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2345
90
Android Chrome Eclipse IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if I write the code in scriptlet, then while converting to servlete, the code goes in service method, so how can I call the doPost method of JSP that is converted to servlet?

Ok, I am now getting your misunderstanding.

The code of a scriptlet in let's say JSP A is placed in the service method of the Servlet created from JSP A. Using a HTML form on the JSP A will issue a new request targeting another Servlet or JSP (depending on the action and the setup in your web.xml).

Regards,
Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic