cse 510 web data engineering
play

CSE 510 Web Data Engineering The Struts Framework Logon Example - PowerPoint PPT Presentation

CSE 510 Web Data Engineering The Struts Framework Logon Example UB CSE 510 Web Data Engineering Example The example implements a dummy logon functionality Do not consider this example to be the best way to implement authorization and


  1. CSE 510 Web Data Engineering The Struts Framework Logon Example UB CSE 510 Web Data Engineering

  2. Example • The example implements a dummy logon functionality – Do not consider this example to be the best way to implement authorization and access control – The example is used only to demonstrate the Struts framework – Appropriate authorization and access control will be covered in a separate lecture shortly 2 UB CSE 510 Web Data Engineering

  3. WorkFlow Start ¡ welcome ¡ Welcome.do ¡ success ¡ forward ¡ Sign ¡in ¡ Submit ¡ (hyperlink) ¡ (buBon) ¡ forward ¡ Welcome.jsp ¡ Logon.jsp ¡ Logon.do ¡ logonForm ¡ LogonSubmit.do ¡ !validate ¡ success ¡ Sign ¡out ¡ (hyperlink) ¡ Logoff.do ¡ 3 UB CSE 510 Web Data Engineering

  4. WorkFlow Start ¡ welcome ¡ Welcome.do ¡ success ¡ forward ¡ Sign ¡in ¡ Submit ¡ (hyperlink) ¡ (buBon) ¡ forward ¡ Welcome.jsp ¡ Logon.jsp ¡ Logon.do ¡ logonForm ¡ LogonSubmit.do ¡ !validate ¡ success ¡ Sign ¡out ¡ get ¡ (hyperlink) ¡ remove ¡ set ¡ user: ¡logonForm ¡ Logoff.do ¡ Session ¡Scope ¡ UserDirectory ¡ isValidPassword(String ¡username, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡String ¡password) ¡ 4 UB CSE 510 Web Data Engineering

  5. /index.jsp <%@ ¡taglib ¡uri="hBp://struts.apache.org/tags-­‑logic" ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡prefix="logic" ¡ %> ¡ <logic:redirect ¡forward="welcome"/> ¡ <%-­‑-­‑ ¡ Redirect ¡default ¡requests ¡to ¡Welcome ¡global ¡AcRonForward. ¡ -­‑-­‑%> ¡ 5 UB CSE 510 Web Data Engineering

  6. /pages/Welcome.jsp <%@ ¡taglib ¡uri="hBp://struts.apache.org/tags-­‑bean" ¡prefix="bean" %> ¡ <%@ ¡taglib ¡uri="hBp://struts.apache.org/tags-­‑html" ¡prefix="html" %> ¡ <%@ ¡taglib ¡uri="hBp://struts.apache.org/tags-­‑logic" ¡prefix="logic" %> ¡ <html:html> ¡ <head> ¡ ¡ ¡ ¡ ¡<Rtle> <bean:message ¡key="app.Atle" ¡/> </Rtle> ¡ ¡ ¡ ¡ ¡ <html:base ¡/> ¡ </head> ¡ <body> ¡ <logic:present ¡name="user"> ¡ ¡ ¡ ¡ ¡<h3>Welcome ¡ <bean:write ¡name="user" ¡property="username" ¡/> !</h3> ¡ </logic:present> ¡ … ¡ 6 UB CSE 510 Web Data Engineering

  7. /pages/Welcome.jsp (cont’d) ... ¡ <logic:notPresent ¡scope="session" ¡name="user"> ¡ ¡ ¡ ¡ ¡<h3><bean:message ¡key="welcome.heading" ¡/></h3> ¡ </logic:notPresent> ¡ <html:errors ¡/> ¡ <ul> ¡ ¡ ¡ ¡ ¡<li> <html:link ¡forward="logon"> Sign ¡in </html:link> </li> ¡ ¡ ¡ ¡ ¡<logic:present ¡name="user"> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<li><html:link ¡forward="logoff">Sign ¡out</html:link></li> ¡ ¡ ¡ ¡ ¡</logic:present> ¡ </ul> ¡ </body> ¡ </html:html> ¡ 7 UB CSE 510 Web Data Engineering

  8. Edge Labels In struts-config.xml <!-­‑-­‑ ¡=========Global ¡Forward ¡DefiniRons ¡  ¡ ¡ ¡ ¡ ¡<global-­‑forwards> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<forward ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡name="logoff" ¡ ¡ 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right"> <html:submit ¡/> </td> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<td> <html:reset ¡/> </td></tr> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡</table> ¡ ¡ ¡ ¡ ¡</html:form> ¡ </body> ¡ … ¡ 9 UB CSE 510 Web Data Engineering

  10. Associating the ActionForm Bean with the HTML Form <acRon ¡ ¡ ¡ ¡ ¡ ¡path="/LogonSubmit” ¡ ¡ ¡ ¡ ¡type="app.LogonAcAon" ¡ ¡ ¡ ¡ ¡name="logonForm" ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡scope="request" ¡ ¡ ¡ ¡ ¡validate="true" ¡ ¡ ¡ ¡ ¡input="/pages/Logon.jsp"> ¡ ¡ ¡ ¡ ¡<forward ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡name="success" ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡path="/pages/Welcome.jsp"/> ¡ </acRon> ¡ 10 UB CSE 510 Web Data Engineering

  11. Form Beans Also Provide Values /pages/Logon.jsp … ¡ ¡ ¡ ¡ ¡<h3><bean:message ¡key=”logon.heading" ¡/></h3> ¡ ¡ ¡ ¡ ¡ <html:form ¡acAon="/LogonSubmit" ¡focus="username"> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<table ¡width="100%"> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<tr><th ¡align="right">Username:</th> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<td> <html:text ¡property="username" ¡/> </td></tr> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<tr><th ¡align="right">Password:</th> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<td> <html:password ¡property="password" ¡/> </td></tr> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<tr><td ¡align="right"><html:submit ¡/></td> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡<td><html:reset ¡/></td></tr> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡</table> ¡ ¡ ¡ ¡ ¡</html:form> ¡ … ¡ 11 UB CSE 510 Web Data Engineering

  12. Typical Code Of A LogonForm Bean public ¡final ¡class ¡LogonForm ¡extends ¡AcRonForm ¡{ ¡ ¡ ¡ ¡ ¡private ¡String ¡password ¡= ¡null; ¡ ¡ ¡ ¡ ¡private ¡String ¡username ¡= ¡null; ¡ ¡ ¡ ¡ ¡public ¡String ¡getPassword() ¡{ ¡return ¡(this.password); ¡} ¡ ¡ ¡ ¡ ¡public ¡void ¡setPassword(String ¡password) ¡{ ¡this.password ¡= ¡password; ¡} ¡ ¡ ¡ ¡ ¡public ¡String ¡getUsername() ¡{ ¡return ¡(this.username); ¡} ¡ ¡ ¡ ¡ ¡public ¡void ¡setUsername(String ¡username) ¡{ ¡this.username ¡= ¡username; ¡} ¡ ¡ ¡ ¡ ¡public ¡void ¡reset(AcRonMapping ¡mapping, ¡HBpServletRequest ¡request) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡setPassword(null); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡setUsername(null); ¡ ¡ ¡ ¡ ¡} ¡ } ¡ 12 UB CSE 510 Web Data Engineering

  13. The Art of Balancing How Many Actions & JSPs to Use • Consider the “logon” application • We could have one JSP for each kind of login error • However, we will see technologies that help consolidate within a few JSPs – Form validation features – Logic tag library • Deciding the number of actions and JSPs is an art of design – not a science – Examples, practice, then more practice… 13 UB CSE 510 Web Data Engineering

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend