hi
i have to make a image on clicking that an action has to be done
so i made a action class that extends Select
Action class and as the example says i did all the neccessary thing my code is as follow
Action class
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
// Handler of unknown button, which name does not start with button prefix
public ActionForward unspecified(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
System.out.println("--> unspecified");
return mapping.findForward("unspecifiedpage");
}
}
hi
i have to make a image on clicking that an action has to be done
so i made a action class that extends Select
Action class and as the example says i did all the neccessary thing my code is as follow
Action class
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class tabAction extends SelectAction {
// Define mapping from button to method
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("app-submit-button-add", "add");
return map;
}
// Handler of Add button
public ActionForward add(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
System.out.println("--> add");
return mapping.findForward("Page12");
}
// Handler of Delete button
// Handler of unknown button, which name does not start with button prefix
public ActionForward unspecified(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
System.out.println("--> unspecified");
return mapping.findForward("unspecifiedpage");
}
}
struts-config.xml
<action name="loginForm" path="/tabTest1" scope="session" type="com.actions.schd.tabAction" parameter="myapp-submit">
<forward name="Page12" path="/WEB-INF/pages/css/schd/tab2.jsp">
</forward>
and my jsp is
<%@page contentType="text/html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>JSP Page</title>\n\ </head>
<body bgcolor="#FFFFFF">
<html:form action="/tabTest1">
<TABLE border="0" width='100%'>
<TBODY>
<TR>
<TH>Previous Contract Identifier</TH>
<TD><input type="image" src='resources/tabimages/active_inactive.gif' name="myapp-submit-button-add" />
</TR>
</TBODY>
</TABLE>
</html:form>
</body>
</html>
but however when i press the image i get the following error
javax.servlet.ServletException: Dispatch action /tabTest1 returned null or non-string method name for request key myapp-submit-button-add
com.sabc.css.actions.schd.SelectAction.getMethodName(SelectAction.java:256)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:182)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
com.tcs.joa.struts.ActionServlet.process(ActionServlet.java:245)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
can anybody help me and tell me where iam wrong
thanks alot
You are submitting "myapp-submit-button-add" from the form, but you are mapping "app-submit-button-add" in the getKeyMethodMap().
Change the line in getKeyMethodMap as follows:
map.put("myapp-submit-button-add", "add");
and it should work.
Michael.