Hey guys
I'm trying to created a login page using
struts and I'm getting
errors. The page was working when I used ActionForm. But I started
getting errors when I changed to DynaValidatorForm.
I'm learning Struts, so I can't seem to find out where the source of
the problem is.
=====================================
[7/18/06 18:16:37:000 PDT] 00000044 ServletWrappe E SRVE0068E: Could
not invoke the service() method on
servlet /web/pages/login/login.jsp.
Exception thrown : javax.servlet.ServletException: Exception creating
bean of class com.poshWebApp.actions.LoginAction:
java.lang.ClassCastException: com.poshWebApp.actions.LoginAction
at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageCont
extImpl.java:639)
at com.ibm._jsp._login._jspService(_login.java:89)
at
com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:88)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at
com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.
java:1212)
at
com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWr
apper.java:629)
at
com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest
(GenericServletWrapper.java:117)
at
com.ibm.ws.jsp.webcontainerext.JSPExtensionServletWrapper.handleReques
t(JSPExtensionServletWrapper.java:171)
at
com.ibm.ws.jsp.webcontainerext.JSPExtensionProcessor.handleRequest(
JSP ExtensionProcessor.java:230)
at
com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2837)
at
com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:22
0)
at
com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204
)
at
com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1
681)
at
com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java
:77)
at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscriminat
ion(HttpInboundLink.java:421)
at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformat
ion(HttpInboundLink.java:367)
at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInbound
Link.java:276)
at
com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDis
criminaters(NewConnectionInitialReadCallback.java:201)
at
com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(
NewConnectionInitialReadCallback.java:103)
at
com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueue
Manager.java:548)
at
com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManage
r.java:601)
at
com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManage
r.java:934)
at
com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManag
er.java:1021)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1332)
---- Begin backtrace for Nested Throwables
javax.servlet.jsp.JspException: Exception creating bean of class
com.poshWebApp.actions.LoginAction: java.lang.ClassCastException:
com.poshWebApp.actions.LoginAction
at
org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:547)
at
org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:520)
at com.ibm._jsp._login._jspx_meth_html_form_0(_login.java:158)
at com.ibm._jsp._login._jspx_meth_html_html_0(_login.java:196)
at com.ibm._jsp._login._jspService(_login.java:81)
at
com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:88)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at
com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.
java:1212)
at
com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWr
apper.java:629)
at
com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest
(GenericServletWrapper.java:117)
at
com.ibm.ws.jsp.webcontainerext.JSPExtensionServletWrapper.handleReques
t(JSPExtensionServletWrapper.java:171)
at
com.ibm.ws.jsp.webcontainerext.JSPExtensionProcessor.handleRequest(JSP
ExtensionProcessor.java:230)
at
com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2837)
at
com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:22
0)
at
com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204
)
at
com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1
681)
at
com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java
:77)
at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscriminat
ion(HttpInboundLink.java:421)
at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformat
ion(HttpInboundLink.java:367)
at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInbound
Link.java:276)
at
com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDis
criminaters(NewConnectionInitialReadCallback.java:201)
at
com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(
NewConnectionInitialReadCallback.java:103)
at
com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueue
Manager.java:548)
at
com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManage
r.java:601)
at
com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManage
r.java:934)
at
com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManag
er.java:1021)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1332)
==================================================================
LOGIN.JSP
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<html:html>
<head>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META name="GENERATOR" content="IBM Software Development Platform">
<meta http-equiv="Content-Type" content="text/html;">
<title>Untitled</title>
<style>
TD{
font-family:verdana,arial;
color:black;
font-size:8pt;
}
.news{
font-family:arial;
}
.bot{
color:black;
text-decoration:none;
font-size:7pt;
font-family:Verdana;
font-weight:bold;
}
.copy{
font-size:7pt;
color:black;
}
</style>
</head>
<body>
<html:errors/>
<html:form action="/submitLogin"
type="com.poshWebApp.actions.LoginAction" name="LoginForm"
method="POST">
<table border="0" cellpadding="0" cellspacing="0" width="159">
<tr>
<td valign="top" class="news"><b>UserName: </b></td>
<td> <html:text property="userName" size="11" />
</td>
</tr>
<tr>
<td valign="top" class="news"><b>PassWord: </b></td>
<td> <html:text property="passWord" size="11" />
</td>
</tr>
<tr>
<td valign="top"class="news"><INPUT type="submit" value="Logon"></td>
</tr>
</table>
</html:form>
</html:form>
</BODY>
</html:html>
====================================
STUTS_CONFIG.xml
<?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>
<!-- Data Sources -->
<data-sources>
</data-sources>
<!-- Form Beans -->
<form-beans>
<form-bean name="LoginForm"
type="org.apache.struts.validator.DynaValidatorForm">
<!-- Dynamic properties of the Login Form -->
<form-property name="userName"
type="java.lang.String" />
<form-property name="passWord"
type="java.lang.String" />
</form-bean>
</form-beans>
<!-- Global Exceptions -->
<global-exceptions>
</global-exceptions>
<!-- Global Forwards -->
<global-forwards>
</global-forwards>
<!-- Action Mappings -->
<action-mappings>
<action path="/myPath" forward="/main.jsp" />
<action path="/submitLogin" scope="request"
type="com.poshWebApp.actions.LoginAction" name="LoginForm"
validate="false" input="/web/pages/login/login.jsp">
<forward name="success" path="/main.jsp" />
</action>
</action-mappings>
<!-- Message Resources -->
<message-resources
parameter="pbwebapp.resources.ApplicationResources"/>
<!-- Validator Plugin -->
<plug-in
className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml" />
</plug-in>
</struts-config>
===============================================================
LOGINACTION.java
package com.poshWebApp.actions;
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;
/**
* Form bean for a Struts application.
* Users may access 2 fields on this form:
* <ul>
* <li>passWord - [your comment here]
* <li>userName - [your comment here]
* </ul>
* @version 1.0
* @author
*/
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
DynaValidatorForm dynaform = (DynaValidatorForm) form;
dynaform.set("userName", "user name");
dynaform.set("passWord", "password");
request.setAttribute(mapping.getAttribute(), dynaform);
System.out.println("Forwarding - SUCCESS page");
return mapping.findForward("success");
}
}
Please help...Thanks!!!