By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,054 Members | 1,635 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,054 IT Pros & Developers. It's quick & easy.

problem in LookupDispatchAction of Struts

P: 1
[HTML]

When accessing my JSP I get the following error:
org.apache.jasper.JasperException: Missing message for key "button.add"
my error message
Expand|Select|Wrap|Line Numbers
  1. javax.servlet.ServletException: Missing message for key "button.add"
  2.   org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
  3.   org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
  4.   org.apache.jsp.test1_jsp._jspService(test1_jsp.java:103)
  5.   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
  6.   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  7.   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
  8.   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
  9.   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
  10.   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  11.  
my test1.jsp
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
  3. <%@ page import="java.util.Calendar" %>
  4. <%@ page import="java.util.*" %>
  5. <%@ page import="java.lang.*" %>
  6. <%@ page import="java.text.DecimalFormat" %>
  7. <%@ page import="java.sql.*" %>
  8. <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
  9. <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  10. <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
  11. <html>
  12. <body>
  13. <html:form action="/test1" method="get">
  14.     <input type="submit" name="ha1" value="add"/> 
  15.     <input type="submit" name="ha1" value="delete"/>
  16. </html:form>
  17. </body>
  18. </html>
  19.  
my messages.properties
Expand|Select|Wrap|Line Numbers
  1.  
  2. button.add=Add
  3. button.delete=Delete
  4.  
my Action
Expand|Select|Wrap|Line Numbers
  1.  
  2. .....
  3. public class EditAction extends LookupDispatchAction {
  4.  
  5.   private Map map = new HashMap();
  6.   private int addCount;
  7.   private int deleteCount;
  8.   /**
  9.    * Constructor - populate the key method map.
  10.    */
  11.   public EditAction() {
  12.  
  13.     System.out.println("start at Constructor");
  14.     map.put("button.add", "add");
  15.     map.put("button.delete", "delete");
  16.     System.out.println("end at Constructor");
  17.   }
  18.   protected Map getKeyMethodMap() {
  19.     System.out.println("start at getKeyMethodMap");
  20.  
  21.     System.out.println("end at getKeyMethodMap");
  22.     return map;
  23.   }
  24.  
  25.   public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
  26.     throws Exception { 
  27.       // do something here......   
  28.  
  29.       return mapping.findForward("ha"); 
  30.   }
  31.   public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
  32.     throws Exception { // ......   
  33.       // do something here......  
  34.       return mapping.findForward("ha"); 
  35.   }
  36. }
  37.  
my Struts-config.xml
Expand|Select|Wrap|Line Numbers
  1.  
  2. <struts-config>
  3.   <data-sources />  
  4.       <form-bean name="userForm" type="org.apache.struts.action.DynaActionForm">
  5.            <form-property name="testString" type="java.lang.String" />
  6.         </form-bean>
  7.   </form-beans>
  8.   <action-mappings >
  9.    <action path="/test1"  type="test.EditAction" 
  10.            parameter="ha1"
  11.            name="userForm" 
  12.           input="/test1.jsp"
  13.            scope="request" > 
  14.            <!--<exception key="dispatch.ServletException"
  15.                        type="javax.servlet.ServletException"
  16.                        path="/test1.jsp"/> -->        
  17.     <forward  name="ha" path="/test1.jsp" />
  18.   </action>
  19.   </action-mappings>
  20.   <message-resources parameter="MessageResources" />
  21. </struts-config>
  22.  
[/HTML]
Oct 3 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.