• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to call a method from another class

 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to call a method from another class on click of the submit button written inside out.println() method inside my servlet class.
This method creates an excel sheet report.



Can someone please advice me as to how can I call the method on click of the submit button? How can I modify the above statement to call that method?

Thanks in advance,

 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In these way you can't call method from other class.
Call separate servlet on submit(<form action="OtherServlet">) of form & In that (OtherServlet)servlet call method of class that you want..
 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply!

I cannot write another servlet because the instance variable(object) whose method i want to call is created inside this servlet which has the submit button.Is it possible to call this method by some other way inside the same servlet which has the submit button statement?

Please advice

Thanks
 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think any way to call like that.
you can put that object in session and get it fron session in other servlet & call that method.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like you're confusing the server- and client-sides.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The user will have no opportunity to click on the input element until after the servlet has completed and the HTML page has been sent to the browser. From there, you need to deal with clicks with JavaScript.
 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand this.Please can someone explain in more simpler terms as to what can I do to implement this.I am sorry about my ignorance wrt this but I really need to implement this functionality.

I will explain my requirement again:

I have a servlet.Inside this servlet,there is an out.println() statement which has submit button.What I need is to call a method from another class which will open an excel sheet report when the submit button is hit.

Thanks
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, I don't really understand why there's HTML like this being generated in a servlet. HTML belongs in a JSP under almost all circumstances.

Second, you need to create a link or a form that submits to the server side to export the data. Like any other link or form. You don't call anything when you're rendering the HTML, you make the call when they click the export button/link.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML belongs in a JSP under almost all circumstances.


Now, now lets not be doctrinaire about this - I generate lots of html from servlets and practically never use JSP.

Bill
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you're one of the circumstances that aren't "almost all", but that isn't going to change my opinion that HTML generation almost never belongs in Java when much better options exist.

It's precisely *because* of the problems with putting HTML in Java that I say that--not really sure "doctrinaire" applies here, as it has a fairly negative connotation regarding the one making the claim. Either way, that conversation belongs in another thread, not this one.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!