?
Solved

struts dyna form validation example errors

Posted on 2012-08-22
6
Medium Priority
?
802 Views
Last Modified: 2012-10-01
I am running following example on struts dyna form validation example as follows and getting errors.My JSP looks like

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

</body>
</html>

Open in new window



DynamicCustomerAction  looks like this
package actions;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;
public class DynamicCustomerAction extends Action {
&#9;public ActionForward execute(ActionMapping mapping, ActionForm form,
&#9;&#9;&#9;HttpServletRequest request, HttpServletResponse response)
&#9;throws Exception {
&#9;&#9;String nextPage = "success";
&#9;&#9;try {
&#9;&#9;&#9;
&#9;&#9;&#9;DynaValidatorForm bean = (DynaValidatorForm) form;
&#9;&#9;&#9;String firstName = (String) bean.get("firstName");
&#9;&#9;
&#9;&#9;&#9;String middleName = (String) bean.get("middleName");
&#9;&#9;&#9;String lastName = (String) bean.get("lastName");
&#9;&#9;&#9;String age = (String) bean.get("age");
&#9;&#9;&#9;String ssn = (String) bean.get("ssn");
&#9;&#9;&#9;String city = (String) bean.get("city");
&#9;&#9;&#9;String state = (String) bean.get("state");
&#9;&#9;&#9;String country = (String) bean.get("country");
&#9;&#9;
&#9;&#9;&#9;int iage = 0;
&#9;&#9;&#9;int issn = 0;
&#9;&#9;&#9;iage = Integer.parseInt(age);
&#9;&#9;&#9;issn = Integer.parseInt(ssn);
&#9;&#9;&#9;request.getSession(true).setAttribute("Name", firstName + " " +
&#9;&#9;&#9;&#9;&#9;lastName);
&#9;&#9;&#9;
&#9;&#9;} catch (Exception e) {
&#9;&#9;}
&#9;&#9;return mapping.findForward(nextPage);
&#9;}
&#9;private int insertCustomer(String firstName, String middleName,
&#9;&#9;&#9;String lastName, int age, int ssn, String city, String state,
&#9;&#9;&#9;String country) {
&#9;&#9;Connection conn = null;
&#9;&#9;try {
&#9;&#9;&#9;Class.forName("com.mysql.jdbc.Driver");
&#9;&#9;&#9;conn =
&#9;&#9;&#9;&#9;DriverManager.getConnection("jdbc:mysql://localhost:3306/MyDB");
&#9;&#9;} catch (Exception e) {
&#9;&#9;&#9;e.printStackTrace();
&#9;&#9;}
&#9;&#9;int result = -1;
&#9;
&#9;&#9;String sql = "INSERT INTO CUSTOMERS VALUES(?,?,?,?,?,?,?,?);";
&#9;&#9;PreparedStatement ps = null;
&#9;&#9;try {
&#9;&#9;&#9;if (conn != null) {
&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;ps = conn.prepareStatement(sql);
&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;
&#9;&#9;&#9;&#9;ps.setString(1, firstName);
&#9;&#9;&#9;&#9;ps.setString(2, middleName);
&#9;&#9;&#9;&#9;ps.setString(3, lastName);
&#9;&#9;&#9;&#9;ps.setInt(4, age);
&#9;&#9;&#9;&#9;ps.setInt(5, ssn);
&#9;&#9;&#9;&#9;ps.setString(6, city);
&#9;&#9;&#9;&#9;ps.setString(7, state);
&#9;&#9;&#9;&#9;ps.setString(8, country);
&#9;&#9;&#9;&#9;// Execute the prepared statement
&#9;&#9;&#9;&#9;result = ps.executeUpdate();
&#9;&#9;&#9;}
&#9;&#9;} catch (Exception e) {
&#9;&#9;&#9;result = -1;
&#9;&#9;}
&#9;&#9;return result;
&#9;}
}

Open in new window



CustomerDetails looks like
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<html:html>
<BODY>
&#9;<html:errors />
&#9;<P>Please fill in the following details</P>
&#9;<%-- &#9;<html:form action="customer"> --%>
&#9;<html:form action="dynaCustomer">
&#9;&#9;<TABLE border="1">
&#9;&#9;&#9;<TBODY>
&#9;&#9;&#9;&#9;<TR>
&#9;&#9;&#9;&#9;&#9;<TD>FirstName</TD>
&#9;&#9;&#9;&#9;&#9;<TD><html:text property="firstName"></html:text></TD>
&#9;&#9;&#9;&#9;</TR>
&#9;&#9;&#9;&#9;<TR>
&#9;&#9;&#9;&#9;&#9;<TD>MiddleName</TD>
&#9;&#9;&#9;&#9;&#9;<TD><html:text property="middleName"></html:text></TD>
&#9;&#9;&#9;&#9;</TR>
&#9;&#9;&#9;&#9;<TR>
&#9;&#9;&#9;&#9;&#9;<TD>LastName</TD>
&#9;&#9;&#9;&#9;&#9;<TD><html:text property="lastName"></html:text></TD>
&#9;&#9;&#9;&#9;</TR>
&#9;&#9;&#9;&#9;<TR>
&#9;&#9;&#9;&#9;&#9;<TD>Age</TD>
&#9;&#9;&#9;&#9;&#9;<TD><html:text property="age"></html:text></TD>
&#9;&#9;&#9;&#9;</TR>
&#9;&#9;&#9;&#9;<TR>
&#9;&#9;&#9;&#9;&#9;<TD>SSN</TD>
&#9;&#9;&#9;&#9;&#9;<TD><html:text property="ssn"></html:text></TD>
&#9;&#9;&#9;&#9;</TR>
&#9;&#9;&#9;&#9;<TR>
&#9;&#9;&#9;&#9;&#9;<TD>City</TD>
&#9;&#9;&#9;&#9;&#9;<TD><html:text property="city"></html:text></TD>
&#9;&#9;&#9;&#9;</TR>
&#9;&#9;&#9;&#9;<TR>
&#9;&#9;&#9;&#9;&#9;<TD>State</TD>
&#9;&#9;&#9;&#9;&#9;<TD><html:text property="state"></html:text></TD>
&#9;&#9;&#9;&#9;</TR>
&#9;&#9;&#9;&#9;<TR>
&#9;&#9;&#9;&#9;&#9;<TD>Country</TD>
&#9;&#9;&#9;&#9;&#9;<TD><html:text property="country"></html:text></TD>
&#9;&#9;&#9;&#9;</TR>
&#9;&#9;&#9;&#9;<TR>

&#9;&#9;&#9;&#9;&#9;<TD colspan="2"><html:submit></html:submit></TD>
&#9;&#9;&#9;&#9;</TR>
&#9;&#9;&#9;</TBODY>
&#9;&#9;</TABLE>
&#9;</html:form>
</BODY>
</html:html>

Open in new window


Struts-config.xml looks like
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
&#9;<!-- Data Sources -->
&#9;<data-sources></data-sources>
&#9;<!-- Form Beans -->
&#9;<form-beans>
&#9;&#9;<form-bean name="loginForm" type="formbeans.LoginForm">
&#9;&#9;</form-bean>
&#9;&#9;<form-bean name="customerForm" type="formbeans.CustomerForm">
&#9;&#9;</form-bean>



&#9;&#9;<form-bean name="dynamicCustomerForm"
&#9;&#9;&#9;type="org.apache.struts.validator.DynaValidatorForm">
&#9;&#9;&#9;<form-property name="firstName" type="java.lang.String" />
&#9;&#9;&#9;<form-property name="middleName" type="java.lang.String" />
&#9;&#9;&#9;<form-property name="lastName" type="java.lang.String" />
&#9;&#9;&#9;<form-property name="age" type="java.lang.String" />
&#9;&#9;&#9;<form-property name="ssn" type="java.lang.String" />
&#9;&#9;&#9;<form-property name="city" type="java.lang.String" />
&#9;&#9;&#9;<form-property name="state" type="java.lang.String" />
&#9;&#9;&#9;<form-property name="country" type="java.lang.String" />
&#9;&#9;</form-bean>
&#9;</form-beans>
&#9;<!-- Global Exceptions -->
&#9;<global-exceptions></global-exceptions>
&#9;<!-- Global Forwards -->
&#9;<global-forwards></global-forwards>
&#9;<!-- Action Mappings -->
&#9;<action-mappings>
&#9;&#9;<action path="/customer" name="customerForm" validate="true"
&#9;&#9;&#9;input="/jsps/struts/CustomerDetails.jsp" scope="request"
&#9;&#9;&#9;type="actions.CustomerAction">
&#9;&#9;&#9;<forward name="success" path="/jsps/struts/Confirmation.jsp" />
&#9;&#9;</action>
&#9;&#9;<action path="/dynaCustomer" name="dynamicCustomerForm"
&#9;&#9;&#9;type="actions.DynamicCustomerAction ">
&#9;&#9;&#9;<forward name="success" path="/jsps/struts/Confirmation2.jsp" />
&#9;&#9;</action>
&#9;&#9;<action path="/welcome" forward="/jsps/struts/Welcome.jsp" />
&#9;&#9;<action path="/maintenance" type="actions.MaintenanceAction">
&#9;&#9;&#9;<forward name="sales" path="/jsps/struts/Sales.jsp" />
&#9;&#9;&#9;<forward name="inventory" path="/jsps/struts/Inventory.jsp" />
&#9;&#9;</action>
&#9;&#9;<action path="/login" name="loginForm" type="actions.LoginAction">
&#9;&#9;&#9;<forward name="success" path="/jsps/struts/Main.jsp" />
&#9;&#9;</action>
&#9;&#9;<action path="/customTags" type="actions.BeanAction">
&#9;&#9;&#9;<forward name="bean" path="/jsps/struts/BeanTagsDemo.jsp" />
&#9;&#9;</action>
&#9;</action-mappings>
&#9;<!-- Message Resources -->
&#9;<message-resources parameter="myprops.MyStruts" />
</struts-config>

Open in new window

When I run
http://localhost:8080/StrutsReqWithDataNoForm2/jsps/struts/CustomerDetails.jsp leading to

http://localhost:8080/StrutsReqWithDataNoForm2/dynaCustomer.do;jsessionid=71BB08F6A418BFEAF5C8BBB64B617374
giving error as follows
HTTP Status 500 - java.lang.IllegalArgumentException: Resources cannot be null.

--------------------------------------------------------------------------------

type Exception report

message java.lang.IllegalArgumentException: Resources cannot be null.

description The server encountered an internal error (java.lang.IllegalArgumentException: Resources cannot be null.) that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: java.lang.IllegalArgumentException: Resources cannot be null.
&#9;org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
&#9;org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
&#9;org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
&#9;javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
&#9;javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause 

java.lang.IllegalArgumentException: Resources cannot be null.
&#9;org.apache.commons.validator.Validator.<init>(Validator.java:158)
&#9;org.apache.struts.validator.Resources.initValidator(Resources.java:507)
&#9;org.apache.struts.validator.DynaValidatorForm.validate(DynaValidatorForm.java:115)
&#9;org.apache.struts.chain.commands.servlet.ValidateActionForm.validate(ValidateActionForm.java:58)
&#9;org.apache.struts.chain.commands.AbstractValidateActionForm.execute(AbstractValidateActionForm.java:120)
&#9;org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
&#9;org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
&#9;org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
&#9;org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
&#9;org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
&#9;org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
&#9;org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
&#9;javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
&#9;javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.29 logs.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.29

Open in new window

DynaValidation.JPG
0
Comment
Question by:gudii9
  • 2
3 Comments
 
LVL 7

Author Comment

by:gudii9
ID: 38354962
please advise
0
 
LVL 7

Author Comment

by:gudii9
ID: 38405784
please advise
0
 
LVL 20

Accepted Solution

by:
Venabili earned 2000 total points
ID: 38411897
And what does the log file say?

Basically there is a misjoined property somewhere - you think it is in place but it either has the wrong size of letters or is mistyped. Which leads to a null.

So what do you have in the tomcat log at the time when you have the UI responding with this?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

864 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