This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

captcha, using simple servlet and struts mapping

 
azhar bharat
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a struts application which uses a captcha in one of its forms.
The captcha is generated by a simple servlet.
Currently i have a mapping in the web.xml for the servlet.

And in my form in i use "html:image" tag to display the captcha image.

So, here are my questions:
1) Can I map simple servlet like the one above directly in my struts-config xml file, instead of using web.xml?
I am considering this so that in an event of change, i need to change only the struts-config file.
Please treat this as general question and not just with respect to captcha service because I have to use 2 more servlets in my application.

2) I was curious if i can use global-forward for this captcha image. If so how to do it?
I tried using global-forward but was not successfull
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A forward isn't going to work in this situation because you're not forwarding, but including. An image is included as a part of a page, while a forward passes control on to another page.

If you want to have only the struts action servlet defined in your web.xml file, I'd suggest taking the same basic logic you put in your captcha servlet and creating a captcha action. You can then render the image through an <html:image> tag just as you're now doing with the servlet.
 
azhar bharat
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If you want to have only the struts action servlet defined in your web.xml file, I'd suggest taking the same basic logic you put in your captcha servlet and creating a captcha action. You can then render the image through an <html:image> tag just as you're now doing with the servlet.


Then do I return null instead of forwardaction in the action servlet?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's exactly right.

There's even an example of this in the struts-examples.war file that comes with the download. Check out org.apache.struts.webapp.exercise.ImageAction.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic