Solved

<html:form> tag gives me headache!!!!!

Posted on 2004-08-10
6
945 Views
Last Modified: 2012-06-21
Problem #1
========
I am having a jsp compilation problem when I replace <FORM...>..</FORM> with <html:form...></html:form>. It seems <html:form> looks for struts-config information during the jsp compile time (attempting to link the corresponding ActionForm class). The servlet threw an exception as following:

javax.servlet.ServletException: Cannot find ActionMappings or ActionFormBeans collection
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
      org.apache.jsp.login_jsp._jspService(login_jsp.java:88)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

root cause

javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
      org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:798)
      org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:506)
      org.apache.jsp.login_jsp._jspx_meth_html_form_0(login_jsp.java:140)
      org.apache.jsp.login_jsp._jspx_meth_html_html_0(login_jsp.java:114)
      org.apache.jsp.login_jsp._jspService(login_jsp.java:78)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)



Problem #2
=========
ok. I am using the old <FORM...>..</FORM. for the monment....

1. I placed the following statement in my jsp file.
<bean:message key="loginForm.label.readerid"/>
2. Add the following statement at the bottom of my struts-config.xml
<message-resources parameter="ApplicationResources" null="false" />
3. create an ApplicationResources.properties and place it into /WEB-INF/classes directory.

the servlet threw a different exception during the jsp compilation...

javax.servlet.ServletException: Cannot find message resources under key org.apache.struts.action.MESSAGE
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
      org.apache.jsp.login_jsp._jspService(login_jsp.java:79)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

root cause

javax.servlet.jsp.JspException: Cannot find message resources under key org.apache.struts.action.MESSAGE
      org.apache.struts.util.RequestUtils.retrieveMessageResources(RequestUtils.java:1103)
      org.apache.struts.util.RequestUtils.message(RequestUtils.java:1043)
      org.apache.struts.taglib.bean.MessageTag.doStartTag(MessageTag.java:294)
      org.apache.jsp.login_jsp._jspx_meth_bean_message_0(login_jsp.java:178)
      org.apache.jsp.login_jsp._jspx_meth_html_html_0(login_jsp.java:115)
      org.apache.jsp.login_jsp._jspService(login_jsp.java:69)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


Any info would be grateful. Many thanks.
Poor soul
0
Comment
Question by:zollen
6 Comments
 
LVL 9

Accepted Solution

by:
nimaig earned 100 total points
ID: 11769922
Check for these if you have done it correctly :

1. You must have struts-config.xml
2. The path of the struts-config.xml must be specified in web.xml as init-param for ActionServlet.
            <init-param>
                        <param-name>config</param-name>
                        <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
3. When you use <html:form...> </html:form>, you must have the action property defined.
4. This action entry must be available in struts-config.xml.
5. All the related classes must be in the classpath.
6. If you have only applicationresource.properties file then it is better to specify it in web.xml
            <init-param>
                  <param-name>application</param-name>
                  <param-value>com.resource.ApplicationResources</param-value>
    </init-param>
   
    You can put it in struts config.xml aswell
   
    <message-resources key="MESSAGE_KEY" parameter="com.resource.ApplicationResources"/>
   
    here ApplicationResources.properties is lying in 'WEB-INF/classes/com/resource' directory.
    Don't put ApplicationResources.properties directly in the classes as struts fails to pick it up.
    Put it in some directory under classes.
7. The message you are trying to get in .jsp page but be defined in ApplicationResources.properties.
   
   

0
 
LVL 1

Expert Comment

by:quddhus
ID: 11772492
<%@ taglib uri="WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri = "WEB-INF/struts-logic.tld" prefix = "logic"%>

<html>
<title>Test Form</title>
<body>
    <html:form name='UserLoginForm' action='/processForm.do' method='post'>
     ................
     ................
     </html:form>
</body>
</html>

The UserLoginForm.java should be defined in struts-config.xml
<form-bean name="UserLoginForm" type="com.test.UserLoginForm"/>

Also action tagshould be defined
<action name="UserLoginForm" path="/processForm"
             scope="request" type="com.test.UserLoginAction">
             <forward name="success" path="/welcome.jsp"/>
             <forward name="failure" path="/relogin.jsp"/>
</action>

All the best...


0
 
LVL 9

Expert Comment

by:nimaig
ID: 11773320
Check for 'WEB-INF' directory. It must be uppercase and not 'web-inf'
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 5

Expert Comment

by:KarcOrigin
ID: 11780360
Hi,
Could you please send struts-config file contents.
Karc
0
 

Author Comment

by:zollen
ID: 11784956
I have solved the problems! struts-config information must be availabe before the execution of <html:form> tag. Therefore ActionServlet must be loaded on startup first.


Login authentication is obviously done in LoginAction class. If a "login failure" msg need to be printed by <html:errors/>, can I create an ActionError object in LoginAction class? if so, how to use ActionError object in LoginAction class?

 
0
 

Author Comment

by:zollen
ID: 11785032
How could I use ActionMessage object in LoginAction??
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This problem is more common than not and I will show you some things to check to solve this problem.
February 24, 2017 — On February 23, Travis Ormandy, a vulnerability researcher at Google, reported on Twitter (https://twitter.com/taviso/status/834900838837411840) that massive stores of data have been leaked by CloudFlare, a company that provide…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question