Verwendung von DynActionForm (Struts)

Status
Nicht offen für weitere Antworten.

Bigelo

Mitglied
Hallo.

Ich habe bisher für meine kleine Webanwendung mit eigen erstellten Action Forms gearbeitet. Nun wollte ich mal DynActionForms verwenden um mir die lästige Erstellung von Java Klassen, welche für jedes Form bean von nöten sind, zu ersparen.

Ich greife dann in meiner Action auf folgendem Wege duf die Elemente zu:

DynaActionForm df = (DynaActionForm)form;
String name = (String)df.get("name");
String passwort = (string)df.get("passwort");


Wen ich nun meine Anwendung ausführe, kommt folgender Fehler:

javax.servlet.ServletException: org.apache.struts.action.DynaActionForm
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.ClassCastException: org.apache.struts.action.DynaActionForm
login_package.LoginAction.execute(LoginAction.java:40)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

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





Ich glaube nicht das es mit dem Zugriff auf die Elemente zu tun hat, habe aber auch keine Idee woran es liegen könnte.

Wäre echt super, wenn mir jemand helfen könnte.

P.S.: Gibt es eigentlich einen Nachteil an DynActionForms gegenüber selbsteschriebenen ActionForms?


Danke
 

Bigelo

Mitglied
struts-config.xml:


<form-bean name="loginForm"
type="org.apache.struts.action.DynaActionForm"
dynamic="true">
<form-property name="name"
type="java.lang.String"
initial="Peter"/>
<form-property name="password"
type="java.lang.String"
initial=""/>
</form-bean>
 

clemson

Bekanntes Mitglied
hmm, und wie schaut das action-mapping aus (da, wo du festlegst, welche actio welche actionform hat)?

Code:
DynaActionForm df = (DynaActionForm)form;
String name = (String)df.get("name");
String passwort = (string)df.get("passwort");

das kleingschriebene string ist nur ein rechtschreibfehler von dir beim posten, oder?


ps.: es gibt auch die DynaActionForm#getString(String) methode, welche dir das casten erspart...
 

Bigelo

Mitglied
ja, das war nur ein Rechtschreibfehler vom posten

Hier ist das action-mapping:

<action path="/login"
type="login_package.LoginAction"
name="loginForm"
scope="request"
input="/login.jsp"
validate="true">
<forward name="failure" path="/login.jsp"/>
<forward name="success" path="/loggedin.jsp"/>
</action>
 

clemson

Bekanntes Mitglied
hmm, soweit schaut alles in ordnung aus...

überprüfe mal, was denn für ein typ zurückgegeben wird!

Code:
DynaActionForm daf = (DynaActionForm) form;
Object o = daf.get("name");
System.out.println( o.getClass().getName() );
 

Bigelo

Mitglied
Hmm..., scheint damit nichts zu tun zu haben.

Es handelt sich bei dem Teil der Anwendung, in dem ich die DynActionForm verwende, um eine Login Maske. Wenn ich mich mit korrektem Passwort einlogge, wird direkt die obige Fehlermeldung angezeigt und egal wie ich den Code in der Action ändere, wird immer Zeile 40 in meiner Action Klasse als Fehlerstelle angezeigt.
 

Bigelo

Mitglied
Hi!
Hier ist die LoginAction:

Code:
package login_package;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynActionForm;



/** the purpose of a Action subclass is to process the user's request
 * 
 * @author Benjamin
 *
 */
public class LoginAction extends Action 
{
	/**
	 * Handles user's request for login
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @throws Exception
	 * @return ActionForward
	 */
	public ActionForward execute( 	ActionMapping mapping,
									ActionForm form,
									HttpServletRequest request,
									HttpServletResponse response)
									throws Exception
	{
		
		DynaActionForm df = (DynaActionForm)form;
		Object o = df.get("name");
		System.out.println (o.getClass().getName());
		
		
		// create a new LoginBean with valid users in it. It represents the Model and holds the data regarding    
                authorized users
		LoginBean lb = new LoginBean(getDataSource(request, "kms_db"));
		
		
		
		
		
		
			
		
		
		
		UserDTO user = lb.validateUser(	name,passwort);

		
		
		
		
		
		if (user != null){
			//Save UserDTO in the Session
			request.getSession().setAttribute("user", user);
			return (mapping.findForward("success"));
		}
		//if username an password not validated
		else{
			// create ActionError and save in the request
			ActionErrors errors = new ActionErrors();
			ActionError error = new ActionError("error.login.invalid");
			errors.add("login",error);
			saveErrors(request,errors);
			return (mapping.findForward("failure"));
		}
	}
}
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
L JSP Fehlermeldung bei Verwendung von Java-Expression-Language Allgemeines EE 8
S JEE5: Verwendung von zwei Interfaces Allgemeines EE 4
G Neue Session bei der Verwendung von Frames Allgemeines EE 3
S Struts 2 datetimepicker Allgemeines EE 3
W Struts Tutorial für EE Noobs? Allgemeines EE 2
N Struts vs JSF ? Allgemeines EE 7
W Speicher-Problem bei WebApp unter Tomcat, Struts, Hibernate Allgemeines EE 3
Lex Property per html:link schreiben in struts Allgemeines EE 2
Shihan Line Breaks in <br /> umwandeln (Struts) Allgemeines EE 7
S Struts: zwei JSP's nutzen eine Action Allgemeines EE 5
G Struts: ActionMessage value in JSP anzeigen Allgemeines EE 2
S Problem mit Struts und tiles Allgemeines EE 4
S Struts und Session Allgemeines EE 2
K Struts - FormBean mit 2 Listen - Anzeigen und Speichern Allgemeines EE 2
S Probleme mit struts - ActionServlet Allgemeines EE 6
C Struts in iFrame Allgemeines EE 2
Z Struts: Formularfelder initialisieren Allgemeines EE 3
S Struts: Wert in einem iterierten Drop-Down Menü selektieren Allgemeines EE 7
T Struts 2 Allgemeines EE 6
R Struts-Action in JSP abfragen? Allgemeines EE 2
J struts: Bild als submit-button Allgemeines EE 2
J Internationalization mit Struts Allgemeines EE 2
E bei struts inhalte über mehrere seite verteilen Allgemeines EE 6
velaluka Struts- falsches Character-Encoding? Allgemeines EE 3
M URL Darstl. und Struts Allgemeines EE 2
G Struts beans Allgemeines EE 7
D Struts + Table Allgemeines EE 6
L Struts - Action auslösen bei Browser Back Allgemeines EE 2
N Struts - Problem mit <html:link> Action Allgemeines EE 3
netspy Struts, Spring oder ... ? Allgemeines EE 5
S Struts - Direktaufruf eines URL verhindern Allgemeines EE 11
1 Frage zu Struts und findForward Allgemeines EE 4
N Struts Jboss und Filter Allgemeines EE 2
S Fragen zu: Servlets, Struts & Hibernate Allgemeines EE 9
T Struts und Objekte in Comboboxen Allgemeines EE 4
J Probleme mit Struts Allgemeines EE 3
K STRUTS The server encountered an internal error Allgemeines EE 5
F struts logic:iterate Allgemeines EE 5
M STRUTS/Cannot retrieve definition for form bean null on acti Allgemeines EE 4
G struts-config.xml Allgemeines EE 3
H Ich bin sehr verwirrt - struts, jsp, jsf . ? Allgemeines EE 53
P Testen von Struts-Anwendung Allgemeines EE 7
P Struts Form Bean vs. Session Variable Allgemeines EE 6
A Tomcat undeploy unter Windows klappt nicht wegen struts.jar Allgemeines EE 2
B Struts Problem: Array in JSP ausgeben (logic:iterate) Allgemeines EE 12
M Struts Deployment Allgemeines EE 3
R Mehrsprachige Seite mit Struts & Co. ? Allgemeines EE 5
S mehrere Message Resources in Struts ansprechen Allgemeines EE 7
G Values aus DB in Input-Feldern anzeigen (Struts) Allgemeines EE 2
G Exception creating bean of class . (Struts) Allgemeines EE 8
K dynamischer Zugriff auf .properties (Struts) Allgemeines EE 2
K Struts html:messages tag Allgemeines EE 2
M Struts File Upload problem Allgemeines EE 6
G Validierung mittels Struts. Benötige Hilfe. Allgemeines EE 7
J Buchempfehlung: Servlets, JSP, Struts, JSTL Allgemeines EE 3
P struts "beliebige motive in der datenbank finden" Allgemeines EE 6
P Struts und Frames Allgemeines EE 13
L jfreechart und Struts / JSPs Allgemeines EE 3
P struts Hibernate MySQL Select Statement Allgemeines EE 24
P keine verbindung vom struts framework zu mysql Allgemeines EE 2
R Vernünftige Session-Verwaltung mit Struts Allgemeines EE 4
P Struts Anwendung- FormBean Tabelle mit input type=text Allgemeines EE 2
G Probleme mit Validierung (Struts, validation.xml) Allgemeines EE 4
M Struts - ActionForward Allgemeines EE 9
clemson gesplittete struts-config mittels ant zusammenbauen Allgemeines EE 2
J Struts Textfeld Allgemeines EE 10
M Struts shale Allgemeines EE 7
M Struts - jsp site - werte formatieren Allgemeines EE 6
clemson mehrere Mail Attachments - JSP Struts Allgemeines EE 7
T JSTL + Struts (inkl.Hibernate) -> forEach Problem Allgemeines EE 6
R Struts FormBean Allgemeines EE 4
S Struts 1.1 download einer Datei Allgemeines EE 4
R Use bean in scriptlet in struts Allgemeines EE 4
S reagieren auf select events in jsp-struts seiten Allgemeines EE 5
P Struts - Text formatieren Allgemeines EE 6
C Grafische Komponenten unter Struts jsp (Liste) Allgemeines EE 4
P Struts - Abarbeitung Allgemeines EE 3
P J2EE Struts - Database connection failed - Hilfe?:( Allgemeines EE 6
P J2EE Struts Allgemeines EE 2
R struts 1.0.2 Checkbox-Property bleibt immer false Allgemeines EE 3
TRunKX Werteübergabe von einer *.jsp in eine *.java ohne struts Allgemeines EE 4
clemson [Struts] Validierung server-seitig bringt StackOverflowError Allgemeines EE 5
clemson [Struts] HTML-Checkbox Tag ID Allgemeines EE 2
clemson [Struts] Einer Action Parameter übergeben Allgemeines EE 2
clemson [Struts] Innerhalb Action auf form zugreifen Allgemeines EE 4
G In einer JSP auf Struts-Elemente "reagieren" Allgemeines EE 4
clemson [Struts] struts-config.xml parsen Allgemeines EE 2
clemson [Struts] Parameter an ActionForward anhängen Allgemeines EE 3
clemson [Struts] TilesRequestProcessor - processRoles Allgemeines EE 14
F Struts Allgemeines EE 9
G Struts-Write Anweisungen in Hyperlink einbauen Allgemeines EE 3
G Struts-Form: in validate- oder reset-Methode umleiten. Allgemeines EE 3
G Listenfeld mit Struts und Beans realisieren Allgemeines EE 4
L Anfänger: suche Tutorials zu Struts/EJB Allgemeines EE 6
G Struts - dynamisches FormBean Allgemeines EE 3
R struts und Mapped Properties Allgemeines EE 2
A Javadocs zu struts Allgemeines EE 5
A Kolloquium J2EE / Struts Allgemeines EE 16
A Expression Language in Struts? Allgemeines EE 6
A Form Validierung mit Struts? Allgemeines EE 2

Ähnliche Java Themen

Neue Themen


Oben