File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet code in JSP page

 
Jigar Naik
Ranch Hand
Posts: 761
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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: 761
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know its not good but i have to do what my boss says.
 
Anu Pillai
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • 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: 761
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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: 761
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your boss have pointy hair?
 
Manish Agarwal
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
yu wang
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A jsp is just a servlet. But I think putting all codes into a servlet is a better chance.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic