Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

code written in scriptlet of JSP

 
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?
 
Creator of Enthuware JWS+ V6
Posts: 3343
303
Android Eclipse IDE Chrome
  • 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
Posts: 3343
303
Android Eclipse IDE Chrome
  • 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
Posts: 3343
303
Android Eclipse IDE Chrome
  • 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

 
Rancher
Posts: 43016
76
  • 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
Posts: 3343
303
Android Eclipse IDE Chrome
  • 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
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic