Solved

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

Posted on 2004-08-10
6
919 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now