This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA
We are pleased to have you as a customer!
Here is the information you entered:
Name: | <%= request.getParameter("userName") %> |
---|---|
Street address: | <%= request.getParameter("street") %> |
City: | <%= request.getParameter("city") %> |
State: | <%= request.getParameter("state") %> |
Zip: | <%= request.getParameter("zip") %> |
Credit Card #: | <%= strCardNum %> |
Note: Since you did not enter a credit card number, all orders must be paid in cash on the barrelhead! |
We are pleased to have you as a customer!
Here is the information you entered:
Name: | <%= request.getParameter("userName") %> |
---|---|
Street address: | <%= request.getParameter("street") %> |
City: | <%= request.getParameter("city") %> |
State: | <%= request.getParameter("state") %> |
Zip: | <%= request.getParameter("zip") %> |
Credit Card #: | <%= strCardNum %> |
<jsp:include page="NoCreditCard.html" flush="true" /> |
And we mean it!!!
Register.html same as before
© 2004 SkillBuilders, Inc.
V 3.1
Jav Server Pages: Solutions to Workshops
Page 6
Lesson 5: Using JavaBeans with JSPs Workshop
CustomerBean.java /* Customer String String String String String String
Bean with these read/write properties: userName street city state zip cardNumber
*/ package labs.jspbeans; public class CustomerBean { private String userName private String street private String city private String state private String zip private String cardNumber
= = = = = =
""; ""; ""; ""; ""; "";
//================================================ // String userName property //================================================ public String getUserName() { return userName; } public void setUserName(String value) { userName = value; } //================================================ // String street property //================================================ public String getStreet() { return street; } public void setStreet(String value) { street = value; }
© 2004 SkillBuilders, Inc.
V 3.1
Jav Server Pages: Solutions to Workshops
Page 7
//================================================ // String city property //================================================ public String getCity() { return city; } public void setCity(String value) { city = value; } //================================================ // String state property //================================================ public String getState() { return state; } public void setState(String value) { state = value; } //================================================ // String zip property //================================================ public String getZip() { return zip; } public void setZip(String value) { zip = value; } //================================================ // String cardNumber property //================================================ public String getCardNumber() { return cardNumber; } public void setCardNumber(String value) { cardNumber = value; } }
Welcome.jsp
We are pleased to have you as a customer!
Here is the information you entered:
Name: | <jsp:getProperty name="customer" property="userName" /> |
---|---|
Street address: | <jsp:getProperty name="customer" |
City: | <jsp:getProperty name="customer" |
State: | <jsp:getProperty name="customer" |
Zip: | <jsp:getProperty name="customer" |
Credit Card #: | <jsp:getProperty name="customer" property="cardNumber" /> |
<jsp:include page="NoCreditCard.html" flush="true" /> |
ctlbasic.tld
© 2004 SkillBuilders, Inc.
V 3.1
Jav Server Pages: Solutions to Workshops
Page 10
HitCountTag.java package ctlbasic; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; public class HitCountTag extends TagSupport { private static int _iInstCount; private static int _iCount; public HitCountTag() { System.out.println("Instantiating CounterTag #" + ++_iInstCount); } public int doStartTag() throws JspException { _iCount++; System.out.println("Incrementing counter to " + _iCount); try { JspWriter out = pageContext.getOut(); out.print(_iCount); } catch(java.io.IOException ex) { throw new JspException(ex.getMessage()); } return SKIP_BODY; } }
web.xml <web-app>
© 2004 SkillBuilders, Inc.
V 3.1
Jav Server Pages: Solutions to Workshops
Page 11
Lesson 8: Adding Attributes to Custom Tag Workshop
CounterTest.jsp
Count for Dewey (explicit reset=false):
Count for Louie (default reset):
Count for (parameter):
ctladvanced1.tld
© 2004 SkillBuilders, Inc.
V 3.1
Jav Server Pages: Solutions to Workshops
Page 12
HitCountTag.java package ctladvanced1; import java.util.Hashtable; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.TagSupport; public class HitCountTag extends TagSupport { private static int _iInstCount; // private static int _iCount; private static Hashtable _htCounters = new Hashtable(); private String _strName; private boolean _bReset = false; public HitCountTag() { System.out.println("Instantiating CounterTag #" + ++_iInstCount); } public void setPageContext(PageContext pc) { super.setPageContext(pc); _strName = null; _bReset = false; } // Name attribute public void setName(String value) { _strName = value; } public void setReset(String value) { _bReset = value.toUpperCase().equals("TRUE"); } public int doStartTag() throws JspException { // Get initial count
© 2004 SkillBuilders, Inc.
V 3.1
Jav Server Pages: Solutions to Workshops
Page 13
int iCount = 0; if(! _bReset && _htCounters.containsKey(_strName)) { Integer intCount = (Integer) _htCounters.get(_strName); iCount = intCount.intValue(); } iCount++; try { JspWriter out = pageContext.getOut(); out.print(iCount); // Put new count back into hashtable Integer intCount = new Integer(iCount); _htCounters.put(_strName, intCount); } catch(java.io.IOException ex) { throw new JspException(ex.getMessage()); } return SKIP_BODY; } }
web.xml <web-app>
© 2004 SkillBuilders, Inc.
V 3.1
Jav Server Pages: Solutions to Workshops
Page 14
Lesson 8: Using PageContext Workshop
CounterTest.jsp
Count for Dewey (explicit reset=false):
Count for Louie (default reset):
Count for <%= strName %> (parameter):
ctladvanced2.tld
© 2004 SkillBuilders, Inc.
V 3.1
Jav Server Pages: Solutions to Workshops
Page 15
HitCountTag.java package ctladvanced2; //import java.util.Hashtable; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.TagSupport; public class HitCountTag extends TagSupport { private static int _iInstCount; // private static int _iCount; // private static Hashtable _htCounters = new Hashtable(); private String _strName; private boolean _bReset = false; public HitCountTag() { System.out.println("Instantiating CounterTag #" + ++_iInstCount); } public void setPageContext(PageContext pc) { super.setPageContext(pc); _strName = null; _bReset = false; } // Name attribute public void setName(String value) { _strName = value; } public void setReset(String value) { _bReset = value.toUpperCase().equals("TRUE"); }
© 2004 SkillBuilders, Inc.
V 3.1
Jav Server Pages: Solutions to Workshops
Page 16
public int doStartTag() throws JspException { // Get initial count int iCount = 0; Integer intCount = (Integer) pageContext.getAttribute(_strName, PageContext.APPLICATION_SCOPE); if(! _bReset && intCount != null) { Integer intCount = (Integer) _htCounters.get(_strName); iCount = intCount.intValue(); }
//
iCount++; try { JspWriter out = pageContext.getOut(); out.print(iCount); // Put new count back into hashtable intCount = new Integer(iCount); pageContext.setAttribute(_strName, intCount, PageContext.APPLICATION_SCOPE); } catch(java.io.IOException ex) { throw new JspException(ex.getMessage()); } return SKIP_BODY; } }
web.xml < <web-app>
© 2004 SkillBuilders, Inc.
V 3.1
Jav Server Pages: Solutions to Workshops
Page 17
Lesson 9: Using Body Content Workshop
CompanyBean.java /* Company Bean with these read/write properties: String name String motto */ package ctlbody; public class CompanyBean { private String name = ""; private String motto = ""; //================================================ // String name property //================================================ public String getName() { return name; } public void setName(String value) { name = value; } //================================================ // String motto property //================================================ public String getMotto() { return motto; } public void setMotto(String value) { motto = value; } public String toString() { return "Name: " + name + '\n' + "Motto: " + motto + '\n'; } }
© 2004 SkillBuilders, Inc.
V 3.1
Jav Server Pages: Solutions to Workshops
Page 18
CompanyHeader.jsp <%@ taglib uri='ctlbody' prefix='bod' %>
We are pleased to have you as a customer!
Here is the information you entered:
Name: | <jsp:getProperty name="customer" |
---|---|
Street address: | <jsp:getProperty name="customer" |
City: | <jsp:getProperty name="customer" |
State: | <jsp:getProperty name="customer" |
Zip: | <jsp:getProperty name="customer" |
Credit Card #: | <jsp:getProperty name="customer" property="cardNumber" /> |
<jsp:include page="NoCreditCard.html" flush="true" /> |