Forums Register Login
Servlet code in JSP page
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 ]

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?
I know its not good but i have to do what my boss says.
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'>
No the view is ready in jsp..see the code


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 ]
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?
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.
Does your boss have pointy hair?
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.
A jsp is just a servlet. But I think putting all codes into a servlet is a better chance.
Let me tell you a story about a man named Jed. He made this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database

This thread has been viewed 2626 times.

All times above are in ranch (not your local) time.
The current ranch time is
Mar 23, 2019 06:23:46.