aspose file tools*
The moose likes Struts and the fly likes captcha, using simple servlet and struts mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "captcha, using simple servlet and struts mapping" Watch "captcha, using simple servlet and struts mapping" New topic
Author

captcha, using simple servlet and struts mapping

azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
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

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87

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

Joined: Feb 15, 2005
Posts: 4864
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: captcha, using simple servlet and struts mapping
 
Similar Threads
Null Pointer when i include struts-html.tld
related to .do and .faces
Problems with PropertyMessageResource
first struts application error
How is the HTML form action created from servlet-mapping url-pattern?