<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 14, comments - 22, trackbacks - 0, articles - 4
      BlogJava :: 首頁 ::  :: 聯(lián)系 :: 聚合  :: 管理

    為了讓大家更方便的了解我這個(gè)設(shè)計(jì),我先把我的一些整體的規(guī)劃都說出來吧,由于我是初學(xué),難免會(huì)參照本書籍來看,我買的是那本孫某女的書《精通:*****》,看了看她前面的介紹,我一看了不得,能出書,寫的還都不錯(cuò),這女的可不得了,漸漸疑惑的地方非常多,比如例子里面注釋都拽上了英語,搞不懂,而當(dāng)我從網(wǎng)上下到電子盜版jakarta struts(我已安下栽說明要求的那樣在24小時(shí)后刪除了)這本書的時(shí)候我才恍然大悟,原來是抄襲啊?至于是誰抄的誰,口說無憑,不能亂誹謗,不過大家心里都該有桿稱!

    下面就是代碼了:
    package com.boya.subject.model;
    public interface Person
    {
    ??? public Long getId();
    ??? public void setId( Long id );
    ??? public String getName();
    ??? public void setName( String name );
    ??? public String getPassword();
    ??? public void setPassword( String password );
    ??? public String getTelphone();
    ??? public void setTelphone( String telphone );
    ??? public String getUser();
    ??? public void setUser( String user );
    ??? public String getType();
    }

    package com.boya.subject.model;
    public abstract class User implements Person
    {
    ??? private Long id;數(shù)據(jù)庫id
    ??? private String user;用戶名
    ??? private String password;密碼
    ??? private String name;姓名
    ??? private String telphone;
    電話

    ??? public Long getId()
    ??? {
    ??????? return id;
    ??? }

    ??? public void setId( Long id )
    ??? {
    ??????? this.id = id;
    ??? }

    ??? public String getName()
    ??? {
    ??????? return name;
    ??? }

    ??? public void setName( String name )
    ??? {
    ??????? this.name = name;
    ??? }

    ??? public String getPassword()
    ??? {
    ??????? return password;
    ??? }

    ??? public void setPassword( String password )
    ??? {
    ??????? this.password = password;
    ??? }

    ??? public String getTelphone()
    ??? {
    ??????? return telphone;
    ??? }

    ??? public void setTelphone( String telphone )
    ??? {
    ??????? this.telphone = telphone;
    ??? }

    ??? public String getUser()
    ??? {
    ??????? return user;
    ??? }

    ??? public void setUser( String user )
    ??? {
    ??????? this.user = user;
    ??? }
    }

    package com.boya.subject.model;
    public class Admin extends User
    {
    ??? private String grade = null;
    管理員權(quán)限

    ??? public String getGrade()
    ??? {
    ??????? return grade;
    ??? }

    ??? public void setGrade( String grade )
    ??? {
    ??????? this.grade = grade;
    ??? }

    ??? public String getType()
    ??? {
    ??????? return "admin";
    ??? }
    }

    package com.boya.subject.model;
    public class Teacher extends User
    {
    ??? private String level;
    教師職稱

    ??? public String getLevel()
    ??? {
    ??????? return level;
    ??? }

    ??? public void setLevel( String level )
    ??? {
    ??????? this.level = level;
    ??? }

    ??? public String getType()
    ??? {
    ??????? return "teacher";
    ??? }
    }

    package com.boya.subject.model;

    public class Student extends User
    {
    ??? private String sn;學(xué)生學(xué)號
    ??? private SchoolClass schoolClass;
    班級

    ??? public SchoolClass getSchoolClass()
    ??? {
    ??????? return schoolClass;
    ??? }

    ??? public void setSchoolClass( SchoolClass schoolClass )
    ??? {
    ??????? this.schoolClass = schoolClass;
    ??? }

    ??? public String getSn()
    ??? {
    ??????? return sn;
    ??? }

    ??? public void setSn( String sn )
    ??? {
    ??????? this.sn = sn;
    ??? }

    ??? public String getType()
    ??? {
    ??????? return "student";
    ??? }
    }

    而對于Action我分別做了一個(gè)抽象類,之后別的從這里繼承
    先是Action的
    package com.boya.subject.controller;

    import java.io.IOException;
    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.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import com.boya.subject.frame.ID;
    import com.boya.subject.frame.ServiceFactory;
    import com.boya.subject.model.Person;
    import com.boya.subject.service.Service;
    import com.boya.subject.util.HtmlUtil;

    public abstract class BaseAction extends Action
    {
    ??? /**
    ???? * 由服務(wù)工廠方法創(chuàng)建服務(wù)
    ???? * @return 數(shù)據(jù)庫操作的服務(wù)
    ???? * 2006-5-16 18:10:04
    ???? */
    ??? public Service getService()
    ??? {
    ??????? ServiceFactory factory = (ServiceFactory) getAppObject( ID.SF );
    ??????? Service service = null;
    ??????? try
    ??????? {
    ??????????? service = factory.createService();
    ??????? }
    ??????? catch ( Exception e )
    ??????? {
    ??????? }
    ??????? return service;
    ??? }

    ??? /**
    ???? * 判斷用戶是否合法登陸
    ???? * @param req
    ???? * @return 用戶是否登陸
    ???? * 2006-5-16 18:11:26
    ???? */
    ??? public boolean isLogin( HttpServletRequest req )
    ??? {
    ??????? if ( getPerson( req ) != null ) return true;
    ??????? else
    ??????????? return false;
    ??? }

    ???
    ??? /**
    ???? * 抽象方法,子類實(shí)現(xiàn)
    ???? * @param mapping
    ???? * @param form
    ???? * @param req
    ???? * @param res
    ???? * @return
    ???? * @throws Exception
    ???? * 2006-5-16 18:12:54
    ???? */
    ??? protected abstract ActionForward executeAction( ActionMapping mapping,
    ??????????? ActionForm form, HttpServletRequest req, HttpServletResponse res )
    ??????????? throws Exception;

    ??? /**
    ???? * 獲取session范圍的用戶
    ???? * @param req
    ???? * @return 當(dāng)前用戶
    ???? * 2006-5-16 18:13:35
    ???? */
    ??? public abstract Person getPerson( HttpServletRequest req );

    ??? /**
    ???? * 父類的執(zhí)行Action
    ???? * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    ???? */
    ??? public ActionForward execute( ActionMapping mapping, ActionForm form,
    ??????????? HttpServletRequest req, HttpServletResponse res ) throws Exception
    ??? {
    ??????? if ( !isLogin( req ) )
    ??????? {
    ??????????? HtmlUtil.callParentGo( res.getWriter(), ID.M_UNLOGIN, ID.P_INDEX );
    ??????????? return null;
    ??????? }
    ??????? return executeAction( mapping, form, req, res );
    ??? }

    ??? /**
    ???? * 刪除session中屬性為attribute的對象
    ???? * @param req
    ???? * @param attribute 對象屬性
    ???? * 2006-5-16 18:16:59
    ???? */
    ??? public void removeSessionObject( HttpServletRequest req, String attribute )
    ??? {
    ??????? HttpSession session = req.getSession();
    ??????? session.removeAttribute( attribute );
    ??? }

    ??? /**
    ???? * 設(shè)置session中屬性為attribute的對象
    ???? * @param req
    ???? * @param attribute 設(shè)置屬性
    ???? * @param o 設(shè)置對象
    ???? * 2006-5-16 18:17:50
    ???? */
    ??? public void setSessionObject( HttpServletRequest req, String attribute,
    ??????????? Object o )
    ??? {
    ??????? req.getSession().setAttribute( attribute, o );
    ??? }

    ??? /**
    ???? * 設(shè)置application中屬性為attribute的對象
    ???? * @param req
    ???? * @param attribute 設(shè)置屬性
    ???? * @param o 設(shè)置對象
    ???? * 2006-5-16 18:17:50
    ???? */
    ??? public void setAppObject( String attribute, Object o )
    ??? {
    ??????? servlet.getServletContext().setAttribute( attribute, o );
    ??? }

    ??? public Object getSessionObject( HttpServletRequest req, String attribute )
    ??? {
    ??????? Object obj = null;
    ??????? HttpSession session = req.getSession( false );
    ??????? if ( session != null ) obj = session.getAttribute( attribute );
    ??????? return obj;
    ??? }

    ??? public Object getAppObject( String attribute )
    ??? {
    ??????? return servlet.getServletContext().getAttribute( attribute );
    ??? }

    ??? public void callParentGo( HttpServletResponse res, String msg, String url )
    ??????????? throws IOException
    ??? {
    ??????? HtmlUtil.callParentGo( res.getWriter(), msg, url );
    ??? }

    ??? public void callMeGo( HttpServletResponse res, String msg, String url )
    ??????????? throws IOException
    ??? {
    ??????? HtmlUtil.callMeGo( res.getWriter(), msg, url );
    ??? }

    ??? public void callBack( HttpServletResponse res, String msg )
    ??????????? throws IOException
    ??? {
    ??????? HtmlUtil.callBack( res.getWriter(), msg );
    ??? }

    ??? public void callMeConfirm( HttpServletResponse res, String msg, String ok,
    ??????????? String no ) throws IOException
    ??? {
    ??????? HtmlUtil.callMeConfirm( res.getWriter(), msg, ok, no );
    ??? }
    }
    再是DispatchAction的
    package com.boya.subject.controller;

    import java.io.IOException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.actions.DispatchAction;
    import com.boya.subject.frame.ID;
    import com.boya.subject.frame.ServiceFactory;
    import com.boya.subject.model.Person;
    import com.boya.subject.service.Service;
    import com.boya.subject.util.HtmlUtil;

    public abstract class BaseDispatchAction extends DispatchAction
    {
    ??? /**
    ???? * 由服務(wù)工廠方法創(chuàng)建服務(wù)
    ???? * @return 數(shù)據(jù)庫操作的服務(wù)
    ???? * 2006-5-16 18:10:04
    ???? */
    ??? public Service getService()
    ??? {
    ??????? ServiceFactory factory = (ServiceFactory) getAppObject( ID.SF );
    ??????? Service service = null;
    ??????? try
    ??????? {
    ??????????? service = factory.createService();
    ??????? }
    ??????? catch ( Exception e )
    ??????? {
    ??????? }
    ??????? return service;
    ??? }

    ??? /**
    ???? * 判斷用戶是否合法登陸
    ???? * @param req
    ???? * @return 用戶是否登陸
    ???? * 2006-5-16 18:11:26
    ???? */
    ??? public boolean isLogin( HttpServletRequest req )
    ??? {
    ??????? if ( getPerson( req ) != null ) return true;
    ??????? else
    ??????????? return false;
    ??? }

    ??? /**
    ???? * 獲取session范圍的用戶
    ???? * @param req
    ???? * @return 當(dāng)前用戶
    ???? * 2006-5-16 18:13:35
    ???? */
    ??? public abstract Person getPerson( HttpServletRequest req );

    ??? /**
    ???? * 父類的執(zhí)行DispatchAction
    ???? * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    ???? */
    ??? public ActionForward execute( ActionMapping mapping, ActionForm form,
    ??????????? HttpServletRequest req, HttpServletResponse res ) throws Exception
    ??? {
    ??????? try
    ??????? {
    ??????????? if ( !isLogin( req ) )
    ??????????? {
    ??????????????? callParentGo( res, ID.M_UNLOGIN, ID.P_INDEX );
    ??????????????? return null;
    ??????????? }
    ??????????? return super.execute( mapping, form, req, res );
    ??????? }
    ??????? catch ( NoSuchMethodException e )
    ??????? {
    ??????????? callBack( res, ID.M_NOMETHOD );
    ??????????? return null;
    ??????? }
    ??? }

    ??? /**
    ???? * 刪除session中屬性為attribute的對象
    ???? * @param req
    ???? * @param attribute 對象屬性
    ???? * 2006-5-16 18:16:59
    ???? */
    ??? public void removeSessionObject( HttpServletRequest req, String attribute )
    ??? {
    ??????? HttpSession session = req.getSession();
    ??????? session.removeAttribute( attribute );
    ??? }

    ??? /**
    ???? * 設(shè)置session中屬性為attribute的對象
    ???? * @param req
    ???? * @param attribute 設(shè)置屬性
    ???? * @param o 設(shè)置對象
    ???? * 2006-5-16 18:17:50
    ???? */
    ??? public void setSessionObject( HttpServletRequest req, String attribute,
    ??????????? Object o )
    ??? {
    ??????? req.getSession().setAttribute( attribute, o );
    ??? }

    ??? /**
    ???? * 設(shè)置application中屬性為attribute的對象
    ???? * @param req
    ???? * @param attribute 設(shè)置屬性
    ???? * @param o 設(shè)置對象
    ???? * 2006-5-16 18:17:50
    ???? */
    ??? public void setAppObject( String attribute, Object o )
    ??? {
    ??????? servlet.getServletContext().setAttribute( attribute, o );
    ??? }

    ??? public Object getSessionObject( HttpServletRequest req, String attribute )
    ??? {
    ??????? Object obj = null;
    ??????? HttpSession session = req.getSession( false );
    ??????? if ( session != null ) obj = session.getAttribute( attribute );
    ??????? return obj;
    ??? }

    ??? public Object getAppObject( String attribute )
    ??? {
    ??????? return servlet.getServletContext().getAttribute( attribute );
    ??? }

    ??? public void callParentGo( HttpServletResponse res, String msg, String url )
    ??????????? throws IOException
    ??? {
    ??????? HtmlUtil.callParentGo( res.getWriter(), msg, url );
    ??? }

    ??? public void callMeGo( HttpServletResponse res, String msg, String url )
    ??????????? throws IOException
    ??? {
    ??????? HtmlUtil.callMeGo( res.getWriter(), msg, url );
    ??? }

    ??? public void callBack( HttpServletResponse res, String msg )
    ??????????? throws IOException
    ??? {
    ??????? HtmlUtil.callBack( res.getWriter(), msg );
    ??? }

    ??? public void callMeConfirm( HttpServletResponse res, String msg, String ok,
    ??????????? String no ) throws IOException
    ??? {
    ??????? HtmlUtil.callMeConfirm( res.getWriter(), msg, ok, no );
    ??? }
    }

    對于程序中的一些提示信息,我比較喜歡用JS來寫,所以我把這些都放到了一個(gè)類中
    import java.io.IOException;
    import java.io.Writer;

    public class HtmlUtil
    {
    ??? public static void callParentGo( Writer out, String msg, String url )
    ??????????? throws IOException
    ??? {
    ??????? out.write( "<script language=\"javascript\">" );
    ??????? out.write( "alert(\"" + msg + "\");" );
    ??????? out.write( "parent.location.href=\"" + url + "\";" );
    ??????? out.write( "</script>" );
    ??? }

    ??? public static void callMeGo( Writer out, String msg, String url )
    ??????????? throws IOException
    ??? {
    ??????? out.write( "<script language=\"javascript\">" );
    ??????? out.write( "alert(\"" + msg + "\");" );
    ??????? out.write( "location.href=\"" + url + "\";" );
    ??????? out.write( "</script>" );
    ??? }

    ??? public static void callMeConfirm( Writer out, String msg ,String ok, String no )
    ??????????? throws IOException
    ??? {
    ??????? out.write( "<script language=\"javascript\">" );
    ??????? out.write( "if(window.confirm(\"" + msg + "\")){" );
    ??????? out.write( "location.href=\"" + ok + "\"}else{" );
    ??????? out.write( "location.href=\"" + no + "\"}" );
    ??????? out.write( "</script>" );
    ??? }

    ??? public static void callBack( Writer out, String msg ) throws IOException
    ??? {
    ??????? out.write( "<script language=\"javascript\">" );
    ??????? out.write( "alert(\"" + msg + "\");" );
    ??????? out.write( "parent.history.back();" );
    ??????? out.write( "</script>" );
    ??? }
    }


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    有事在這里給我留言噢!
    主站蜘蛛池模板: 亚洲一区二区影院| 久久亚洲中文无码咪咪爱| 免费人成网站在线观看10分钟| 国产精品亚洲精品观看不卡| 国产免费啪嗒啪嗒视频看看| 免费91麻豆精品国产自产在线观看| 亚洲人配人种jizz| 最新精品亚洲成a人在线观看| 国产成人免费午夜在线观看| 免费人成再在线观看网站| 在线免费观看亚洲| 一本色道久久88亚洲综合| 99热精品在线免费观看| 国产亚洲情侣久久精品| 亚洲视频免费在线观看| 免费a在线观看播放| 亚洲黄色免费电影| jzzjzz免费观看大片免费| 国产AV旡码专区亚洲AV苍井空| 国产亚洲精品免费视频播放| 无码中文字幕av免费放| 国产羞羞的视频在线观看免费| 亚洲国产精品成人AV在线 | 91天堂素人精品系列全集亚洲| 国产小视频免费观看| 最近中文字幕免费2019| 夜夜爽妓女8888视频免费观看| 亚洲精品国产精品国自产网站 | 亚洲AV无码专区在线亚| 国产AV无码专区亚洲精品| 四虎影视永久免费观看| 99在线精品免费视频九九视| 99精品视频免费| 免费观看四虎精品成人| 亚洲人成无码网站在线观看| 亚洲精品综合久久中文字幕| 亚洲欧洲美洲无码精品VA| 亚洲国产精品一区二区三区久久 | 综合在线免费视频| 久久免费高清视频| fc2免费人成在线视频|