Currently I have a servlet CsmServlet.java which is getting called by the client side, here is the web.xml part
<servlet>
<display-name>upload</display-name>
<servlet-name>upload</servlet-name>
<servlet-class>com.abc.csm.web.CsmServlet</servlet-class>
</servlet>
which is perfect. Now I have to use struts 2 and re factor all of my code so what shall i use in my struts.xml to call CsmServlet class.
Here is my struts.xml, right now i am making a redirect to a another page
<struts>
<package name="default" extends="struts-default" namespace="/">
<action name="showResult">
<result>/csminfo.jsp</result>
</action>
</package>
</struts>
I’ll repeat my question,
- What shall i add to my struts.xml to make a request to CsmServlet class
- Do I require any changes in my web.inf?
My Servlet content
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PrintWriter out = resp.getWriter();
Map<String, String> requestParamter=getParamMap(req.getParameterMap());
RequestTransformer transformer = new RequestTransformer(req);
//(map and operation type) goes to CSMData
CSMData data = transformer.transform(requestParamter);
RequestHandler handler = new RequestHandler(req);
String result = handler.handle(data);
log.info(result);
out.println(result);
}
private Map<String,String> getParamMap(Map<String,String[]> params)
{
Map<String,String> paramsMap = new HashMap<String, String>();
for(Map.Entry<String,String[]> entry : params.entrySet())
{
paramsMap.put(entry.getKey(),entry.getValue()[0]);
}
return paramsMap;
}
As Struts implements the MVC architecture, ideally you would not want to have your servlet doing the controlling part. You may want to copy the logic from your servlet to the Struts action.
In general, you would have two options:
controllers) and let the struts
handle controlling. Copy the
business logic from servlets (if
any) into the actions of struts.
Hope this helps.