How can I make own ActionServlet? with example

Answer Posted / ashwin k j

You can make your own ActionServlet by extending
RequestProcessor class and overriding its methods. The
example is given below....

package com.visualbuilder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.RequestProcessor;

public class CustomRequestProcessor extends
RequestProcessor {

public boolean processPreprocess(HttpServletRequest
request, HttpServletResponse response) {

System.out.println("Called the preprocess method before
processing the request");
return super.processPreprocess(request,response);
}
}
The following is web.xml file u should change it accoringly

<?xml version="1.0" encoding="UTF-8"?><web-app
version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-
app_2_4.xsd"><servlet> <servlet-name>action</servlet-
name> <servlet-
class>com.visualbuilder.CustomActionServlet</servlet-
class> <init-param> <param-name>config</param-
name> <param-value>/WEB-INF/struts-config.xml</param-
value> </init-param> <load-on-startup>2</load-on-
startup></servlet><servlet-mapping> <servlet-
name>action</servlet-name> <url-pattern>*.do</url-
pattern></servlet-mapping><welcome-file-list> <welcome-
file>index.jsp</welcome-file></welcome-file-list></web-app>

Is This Answer Correct ?    22 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Give an example where struts tiles may be used?

563


Why struts 1 classes are not thread safe whereas struts 2 classes are thread safe?

510


What are disadvantages of Struts?

564


Is struts compatible with other java technologies?

543


What inbuilt themes are provided by struts2?

599






What are the features of struts?

583


What is difference between spring and struts?

512


How can we work with error tags?

561


What’s the difference between struts and turbine? What’s the difference between struts and espresso?

532


Are struts thread safe?

568


What is struts and springs in java?

540


What is difference between actionform and dynaactionform?

602


in struts how to use hibernate with struts>

1835


What is the significance of logic tags in Struts?

589


What is struts.devmode?

584