Toolkit for Java pages

Source: Internet
Author: User

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.

    1. According to the original example: To do a com.myweb package of toolkit Com.myweb.tool
    2. Creating interfaces uniformly for the navigation bar
    3. Once created, to create some navigation bars on the page, divided into the top navigation bar and the bottom navigation bar
    4. Create a factory and use the factory to generate the top navigation bar and the bottom navigation bar
    5. 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" >          &copy Sun         </div>    </body>
JSP loading navigation bar

Toolkit for Java pages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.