ERLEDIGT
NEIN
NEIN
ANTWORTEN
2
2
ZUGRIFFE
1921
1921
EMPFEHLEN
-
22.12.06 10:39 #1
- Registriert seit
- Sep 2004
- Beiträge
- 90
Hi Leute,
allsooo habe da ein J2EE Projekt mit Struts und Tiles.
Ganz klassich werden Formulareingeaben zunächst durchs FormBean und danach durch die FormAction gejagd und entweder FormBean oder FormAction schmeisst hallt bei Fehlern, error Raus, welche denn auf der <forward failure> page angezeigt werden.
Soweit so gut funktioniert auch alles, AABER: ich benutze auch noch das TILES Framework.
Wird nun eine Error Seite angezeigt, passiert dies ohne jegliche Einbettung in das Layout,
es resultiert wirklich nur die Seite ohne Header / Footer, die das Layout ausmachen.
Jemand ne Ahnung was ich falsch gemacht habe?
Hier mal meine TILES-Def.xml:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd"> <tiles-definitions> <!-- Definition der globalen Einstellungen --> <definition name="base.definition" path="/jsp/layout.jsp"> <put name="title" value="Test" /> <put name="logo" value="images/logo.gif" /> <put name="favicon" value="favicon.ico" /> </definition> <!-- Login Seiten Definition --> <definition name="page.login" extends="base.definition" path="/jsp/layout.jsp"> <put name="body" value="/jsp/index.jsp" /> </definition> <!-- Monitor Definition --> <definition name="page.monitor" extends="base.definition"> <put name="body" value="/jsp/monitor.jsp" /> </definition> </tiles-definitions>
und hier die struts-config:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
<?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 /> <form-beans> <form-bean name="LoginForm" type="xyz.webtransportmonitor.forms.LoginForm"/> </form-beans> <global-exceptions /> <global-forwards > <forward name="showWelcome" path="/showWelcome.do" redirect="true" /> <forward name="showMonitor" path="/showMonitor.do" redirect="true" /> </global-forwards> <action-mappings> <action forward="page.login" path="/showWelcome" /> <action input="/jsp/index.jsp" name="LoginForm" path="/doLogin" scope="request" type="xyz.webtransportmonitor.actions.LoginAction"> <forward name="failure" path="page.login" /> <forward name="success" path="page.monitor" /> </action> </action-mappings> <message-resources parameter="xyz.webtransportmonitor.ApplicationResources" /> <plug-in className="org.apache.struts.tiles.TilesPlugin"> <set-property property="definitions-parser-validate" value="true" /> <set-property property="moduleAware" value="true" /> <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" /> </plug-in> </struts-config>
hier ein beispiel (login):
login-jsp:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<%@ page language="java" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested"%> <div class="introtext"> <h1> Anmeldung </h1> Bitte loggen Sie sich mit Ihren Benutzerdaten ein <html:form action="/doLogin"> <table class=normal> <tr> <td> Username </td> <td> <html:text property="uname" size="30" maxlength="30"/> </td> </tr> <tr> <td> Passwort </td> <td> <html:password property="upwd" size="30" maxlength="30"/> </td> </tr> </table> <font color="red"><html:errors/></font> <p/> <html:submit>Einloggen</html:submit> </html:form> </div>
login-formbean:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
package xyz.webtransportmonitor.forms; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; public class LoginForm extends ActionForm { private static final long serialVersionUID = 6573055891392624314L; // Login-Parameters from Form private String uname = null; //submitted username private String upwd = null; //submitted password public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); //username present? if ( getUname()==null || getUname().length() < 1) { errors.add("uname",new ActionError("error.username.required")); } //userpassword present? if (getUpwd()==null || getUpwd().length() < 1) { errors.add("upwd",new ActionError("error.password.required")); } //Return of possible error-messages in error object return errors; } /* * Getters and Setters */ public String getUname() { return uname; } public String getUpwd() { return upwd; } public void setUname(String uname) { this.uname = uname; } public void setUpwd(String upwd) { this.upwd = upwd; } }
login:action:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
package xyz.webtransportmonitor.actions; import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; import java.util.ListIterator; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; 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 xyz.webtransportmonitor.Crypt; import xyz.webtransportmonitor.FileAccess; import xyz.webtransportmonitor.Login; import xyz.webtransportmonitor.forms.LoginForm; public class LoginAction extends Action { Login loginListe; FileAccess datei = new FileAccess(); Crypt crypt = new Crypt(); // set up Datetime Format DateFormat date_german_long = DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat.MEDIUM, Locale.GERMANY); public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ //hier den check, ob der user gültig ist boolean loginStatus=false; //get entered values LoginForm objForm = (LoginForm) form; String user_username =objForm.getUname(); String user_password =objForm.getUpwd(); //Check if Username is correct if (checkLogin(user_username, user_password) == true) { // User ist vorhanden und wurde authentifiziert loginStatus=true; } else { // Userpasswort hat nicht gestimmt loginStatus=false; } //check if login was successfull if (loginStatus==true) { //Get current session and paste parameters from form //Vorname, nachname, username, passwort, email in session packen HttpSession session = request.getSession(); ArrayList daten = datei.readData(); ListIterator li = daten.listIterator(); while (li.hasNext()) { this.loginListe = (Login) li.next(); String vorname = this.loginListe.getVorname(); String nachname = this.loginListe.getNachname(); String email = this.loginListe.getEmail(); String passwort = this.loginListe.getPasswort(); String loginzeit = this.loginListe.getLetzterLogin(); String tmpUsername = vorname + " " + nachname; if (user_username.equalsIgnoreCase(tmpUsername)) { //User found, set up session vars session.setAttribute("vorname", vorname); session.setAttribute("nachname", nachname); session.setAttribute("username", tmpUsername); session.setAttribute("email", email); session.setAttribute("passwort", passwort); session.setAttribute("loginzeit", loginzeit); //set up empty selection vars session.setAttribute("parameter_belegnummer", ""); session.setAttribute("parameter_debitornummer", ""); session.setAttribute("parameter_wenummer", ""); } } //procceed login doLogin(user_username); //Everything went fine - return success page return mapping.findForward("success"); } else { //Creats error-object ActionErrors errors = new ActionErrors(); errors.add("login",new ActionError("error.nomatchpass")); saveErrors(request,errors); //Errors occured - return error page / login page return mapping.findForward("failure"); } } /** * Helping Methods for validation and registration of users */ public boolean checkLogin(String UserName, String Passwort) { //checks if user is present in loginfile boolean auth = false; String Passworts = crypt.encrypt(Passwort); //Check if login is in arraylist which includes file-data ArrayList daten = datei.readData(); ListIterator li = daten.listIterator(); while (li.hasNext()) { this.loginListe = (Login) li.next(); String vorname = this.loginListe.getVorname(); String nachname = this.loginListe.getNachname(); String passwort = this.loginListe.getPasswort(); String tmpUsername = vorname + " " + nachname; if (UserName.equalsIgnoreCase(tmpUsername)) { // Username is present in arraylist / file if (Passworts.equals(passwort)) { // Username and Password match auth = true; return auth; } else { // Username and Password doesn't match auth = false; return auth; } } } return auth; } public void doLogin(String Username) { // get current datetime Date tmpDate = new Date(); // Aktueller Timestamp String tmpDateString = date_german_long.format(tmpDate); String letzerLogin = tmpDateString; ArrayList daten = datei.readData(); ListIterator li = daten.listIterator(); while (li.hasNext()) { this.loginListe = (Login) li.next(); String vorname = this.loginListe.getVorname(); String nachname = this.loginListe.getNachname(); String tmpUsername = vorname + " " + nachname; // set current datetime into right user if (tmpUsername.equals(Username)) { this.loginListe.setLetzterLogin(letzerLogin); } } // write arraylist data datei.writeData(daten); } }
-
22.12.06 13:25 #2
- Registriert seit
- Aug 2004
- Beiträge
- 464
Ok.. meine Struts bzw. Tiles Configs sahen bis jetzt immer ein ganzes Stück anders aus.
Aber mal jetzt ganz konkret zu dem hier.
Du solltest deine Forwards nicht auf deine Tiles-definitions machen sondern auf actions (also <action>...</action> in der struts-config) welche ggfs. nur eine ForwardAction darstellen.
Ich vermute das der direkte forward auf das Tile den TilesRequestProcessor aushebelt. Warum dass dann aber überhaupt funktioniert kann ich dir auch nicht wirklich sagen.
Probiers einfach mal so wie ichs dir jetzt gesagt habe. So hab ich das bislang immer gehandhabt und hatte damit keine Probleme. Das komplette Binding der Actions und JSPs sollte in der struts-config bleiben. Die JSPs bzw. Tiles werden nur als parameter bzw. inputs übergeben.
MfG Dominik
P.S. schreib bitte IMMER path="..." als erstes in eine Action... sonst sucht man sich ja dumm und dämlich...
-
Hallo, ich wollte mal fragen ob das Problem mittlerweile gelöst ist, und wenn ja wie?
Ich habe genau das gleiche Problem, dass, sobald ich mit validate=true die Form Validieren lasse das Layout nicht mehr angezeigt wird.
@TheLightning kannst du evtl mal ein beispiel geben, wie es bei dir Funktioniert?
Ich hab in den letzen tagen nichts gefunden wo mal sauber erklärt ist, wie das funktionieren soll
Edit: Manchmal kommt ein Geistesblitz: man muss in der struts config statt der jsp seite die tiles Definition eingeben, dann klappt es
Kann mir jetzt vielleicht noch jemand sagen, wie ich verhindern kann, das beim ersten Aufruf des Formulars die Error Meldungen unterdrückt werden können?Geändert von der2of6 (02.01.07 um 16:47 Uhr)
Ähnliche Themen
-
Struts Modules und tiles
Von sandra1976 im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 0Letzter Beitrag: 24.07.08, 16:46 -
Struts 2 mit Tiles 2 konfigurieren
Von Flo[H] im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 18Letzter Beitrag: 08.10.07, 18:47 -
Deutsche Zeichen mit Struts+Tiles
Von e.motion im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 2Letzter Beitrag: 14.08.05, 16:23 -
Struts und Tiles
Von majobau im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 2Letzter Beitrag: 19.04.05, 16:48 -
struts tiles
Von Franz Degenhardt im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 2Letzter Beitrag: 09.06.04, 15:07





Zitieren
Login





