aspose file tools*
The moose likes JSP and the fly likes Servlet code in JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Servlet code in JSP page" Watch "Servlet code in JSP page" New topic
Author

Servlet code in JSP page

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
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 ]

Jigar Naik


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
I know its not good but i have to do what my boss says.
Anu Pillai
Greenhorn

Joined: Oct 09, 2006
Posts: 28
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

Joined: Dec 12, 2006
Posts: 757
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

Joined: Jan 10, 2002
Posts: 61413
    
  67

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

Joined: Dec 12, 2006
Posts: 757
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

Joined: Dec 11, 2004
Posts: 13410

Does your boss have pointy hair?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Manish Agarwal
Greenhorn

Joined: Jan 30, 2006
Posts: 20
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.


SCWCD1.4, SCJP1.4, OCA 9i
yu wang
Greenhorn

Joined: Dec 12, 2006
Posts: 4
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
 
subject: Servlet code in JSP page