• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to invoke a servlet  RSS feed

 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I have a scenario, in which I need to invoke a Servlet, but I'm not too sure of the correct way of doing it.

I'm on say page x.html, and then click on a link on x.jsp which takes me to y.jsp, on y.jsp, the content that I display has computational logic behhind it i.e. I need to check the database to see if some case holds and then according construct the page.

So I'm asking how I could invoke the Servlet without a button click (soo just by a hyperlink I suppose) and what format do I send this data back to y.jsp, i.e. just text or some data structure, if so, which one please?

Sorry for the long winded description.

Thanks in advance guys,
Zein
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple, make the URL that is visited upon button click the URL of the servlet.
 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear for your response.

I though the same and have tried this, but end up getting an error.



My JSP reads as follow



I've Googled the issue, and can't seemt to get to the bottom.

Thanks in advance for your pointers.
Regards
Zein
 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh and the method I use in my Servlet is doGet.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<a href="/servlet/package.className">Great Offers for You</a>


That's not going to work.

You need to set up an appropriate mapping for the servlet in your deployment descriptor and then use that in the URL.
[ January 23, 2007: Message edited by: Bear Bibeault ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you are trying to use the invoker servlet. We have an FAQ page explaining how to use that, and why you should not use it: InvokerServlet.
 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fantastic guys, I have it working. The article link Ulf posted was great.

Thank you very much
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope you didn't solve your problem by actually using the invoker?
 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course not Bear, I took Ulf's advice and used the deployment descriptor (web.xml), the article link Ulf posted was just great.
Thanks for your concerns anyway.

Regards
Zein
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whew! Glad to hear that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!