The so-called toolkit, refers to the function of the page is divided into another package inside. Aspects of project management, clear structure, teamwork and so on.
- According to the original example: To do a com.myweb package of toolkit Com.myweb.tool
- Creating interfaces uniformly for the navigation bar
- Once created, to create some navigation bars on the page, divided into the top navigation bar and the bottom navigation bar
- Create a factory and use the factory to generate the top navigation bar and the bottom navigation bar
- Get the created elements and add them to the interface
It sounds a little more complicated, but I feel it's understandable.
The code is as follows;
Package Com.myweb.tool; Public Interface NavBar { // navigation bar Interface public String getbarcontent (); get navigation bar }
Navigation Bar Interface
Package Com.myweb.tool; Public class Implements NavBar { @Override public String getbarcontent () { return "<a Href= ' > Home </a> | <a href= ' > news </a> | <a href= ' > User registration </a> '; }}
Top navigation bar
Package Com.myweb.tool; Public class Implements navbar{ @Override public String getbarcontent () { return "<a Href= ' > Home </a> | <a href= ' > About Us </a> | <a href= "> Job information </a>"; } }
Bottom navigation bar
PackageCom.myweb.tool; Public classBarfactory { Public StaticNavBar Createbar (String type) {NavBar NV; Switch(type) { Case"Top": NV=NewTopbar (); Break; Case"Bottom": NV=NewBottombar (); Break; default: NV=NewTopbar (); Break; } returnNV; }}
Navigation Bar Factory
@Override PublicModelandview HandleRequest (httpservletrequest arg0, HttpServletResponse arg1)throwsException {modelandview mv=NewModelandview (view); /*Topbar Topnav = new Topbar (); Mv.addobject ("Top_nav", Topnav.getbarcontent ()); Bottombar Bottomnav = new Bottombar (); Mv.addobject ("Bottom_nav", Bottomnav.getbarcontent ());*/NavBar Topnav= Barfactory.createbar ("Top"); NavBar Bottomnav= Barfactory.createbar ("Bottom"); Mv.addobject ("Top_nav", Topnav.getbarcontent ()); Mv.addobject ("Bottom_nav", Bottomnav.getbarcontent ()); returnMV; }
Create a navigation bar
<! DOCTYPE html><!--[published at 2015-11-13 12:30:50]--> ${top_nav} </div> <div > body content </div> <div style= "width:100%;height:95px;border-bottom:solid 1px gray;margin-top:500px" > © Sun </div> </body>
JSP loading navigation barToolkit for Java pages