Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Servlet code in JSP page

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to put my this servlet code in to jsp file. I'm already having this view to send mail like there is 3 textbox and 1 textarea. How do i do that. How do this controller's code will be called on clicking send button ?




[ December 12, 2006: Message edited by: Bear Bibeault ]

[BSouther: Added UBB Code Tags]
[ December 13, 2006: Message edited by: Ben Souther ]
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jigar Naik:
I want to put my this servlet code in to jsp file.



Why on earth would you want to do something like that?

If your code is already properly factored into a servlet, why would you throw all best practices to the wind and put it into a JSP?
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know its not good but i have to do what my boss says.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe what you need to do is that, you want to call the servlet from the jsp on clicking a button of the jsp. Either you misunderstood what your boss said or you couldnt frame the question properly. In case you want to call the servlet from the jsp, change the form tag of your jsp to include the name of the servlet in the action attribute.

something like <form action='urlPatternOfServlet'>
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No the view is ready in jsp..see the code

SendMail.jsp


and the logic is in the Servlet sendMail.java

I'm being told to put the whole code of servlet in to this sendMail.jsp page.

and i guess in jsp on clicking submit some code should be called but don't know how to do that. can you suggest me the same...

[BSouther: Added UBB code tags]
[ December 13, 2006: Message edited by: Ben Souther ]
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What your boss is asking you to do is nonsense.

You can't have the code that is supposed to react to the submission of a form in the same JSP that creates that form. The code in the JSP will execute on the server before the form is even sent to the user. Does that make sense?
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya, i told my boss what you said and now he told me to create another jsp page which will be called from sendMail.jsp.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your boss have pointy hair?
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jigar,

In my opinion you can create a method in the new jsp and call that method in the same jsp. This method will be executed when this jsp is called. This way you can add your code in jsp.
This is very bad practice to put java code in jsp but in your case you cant help it.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A jsp is just a servlet. But I think putting all codes into a servlet is a better chance.
reply
    Bookmark Topic Watch Topic
  • New Topic