扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:QQ新人类 来源:yesky 2007年10月30日
关键字:
<%@ page import = "lbm.jsputil.*" %> <jsp:useBean id="_loginJSPBean" class="lbm.examples.LoginJSPBean" scope="session"/> <jsp:setProperty name="_loginJSPBean" property="*"/> <% AbstractJSPBean _abstractJSPBean = _loginJSPBean; %> <%@ include file="includeheader.jsp" %> <html> <head><title>Vote Login</title></head> <body bgcolor="white"> <font size=4> Please enter your Voter ID and Password </font> <font size="3" color="Red"> <jsp:getProperty name="_loginJSPBean" property="errorMsg"/> </font> <font size=3> <form method=post> Voter ID <input type=text name=voterId value=<jsp:getProperty name="_loginJSPBean" property="voterId"/>> Password <input type=password name=password value=<jsp:getProperty name="_loginJSPBean" property="password"/>> <input type=submit value="Login"> </form> </font> </body> </html> <%@ include file="includefooter.jsp" %> |
<jsp:useBean id="_loginJSPBean" class="lbm.examples.LoginJSPBean" scope="session"/> <jsp:setProperty name="_loginJSPBean" property="*"/> |
<% AbstractJSPBean _abstractJSPBean = _loginJSPBean; %> <%@ include file="includeheader.jsp" %> |
<%-- Set the SharedSessionBean --%> <jsp:useBean id="_sharedSessionBean" class="lbm.jsputil.SharedSessionBean" scope="session"/> <% _abstractJSPBean.setSharedSessionBean(_sharedSessionBean); %> <%-- Set implicit Servlet objects --%> <% _abstractJSPBean.setRequest(request); %> <% _abstractJSPBean.setResponse(response); %> <% _abstractJSPBean.setServlet(this); %> <%-- Perform the processing associated with the JSP --%> <% _abstractJSPBean.process(); %> <%-- If getSkipPageOutput equals false, do not output the JSP page --%> <% if (! _abstractJSPBean.getSkipPageOutput()) { %> |
<% _abstractJSPBean.setRequest(request); %> <% _abstractJSPBean.setResponse(response); %> <% _abstractJSPBean.setServlet(this); %> |
package lbm.jsputil; import java.util.*; import javax.servlet.http.*; import javax.servlet.*; public abstract class AbstractJSPBean { /* constants used for _state */ public static final int NEW = 0; public static final int FIRSTPASS = 1; public static final int PROC = 2; public static final int ERR = -1; private int _state; // current state private String _errorMsg; // current message that is being appended during validation private boolean _skipPageOutput; // should the page output be skipped private SharedSessionBean _sharedSessionBean; // used for associating the JSP Bean with the HTTP Session /* standard Servlet objects that need to be setup for each JSP Bean */ protected HttpServletRequest _request; protected HttpServletResponse _response; protected Servlet _servlet; public AbstractJSPBean () { setState(NEW); } protected abstract void beanProcess() throws java.io.IOException; protected abstract void beanFirstPassProcess() throws java.io.IOException; protected abstract void beanFooterProcess() throws java.io.IOException; protected abstract String getJSPCode(); public void process() throws java.io.IOException { setSkipPageOutput(false); // by default do not skip page output. Specific bean process // methods can override it. if (getState() == NEW) { setState(FIRSTPASS); beanFirstPassProcess(); } else { resetErrorMsg(); setState(PROC); beanProcess(); } // validation that all common fields have been properly set by the application // this is actually checking that the code has been written properly String l_err = ""; if (_sharedSessionBean == null) l_err = l_err + "; SharedSessionBean must be set"; if (_request == null) l_err = l_err + "; Request must be set"; if (_response == null) l_err = l_err + "; Response must be set"; if (_servlet == null) l_err = l_err + "; Servlet must be set"; if ( ! l_err.equals("")) throw new IllegalStateException(l_err); } public void footerProcess() throws java.io.IOException { beanFooterProcess(); } protected void addErrorMsg (String addErrorMsg) { if (_errorMsg == null) _errorMsg = addErrorMsg; else _errorMsg = _errorMsg + " <br>\n" + addErrorMsg; setState(ERR); } protected void resetErrorMsg () { _errorMsg = null; } public String getErrorMsg () { if (_errorMsg == null) return ""; else return _errorMsg; } protected void setState (int newState) { _state = newState; } public int getState () { return _state; } public void setSharedSessionBean (SharedSessionBean newSharedSessionBean) { if (_sharedSessionBean == null) { _sharedSessionBean = newSharedSessionBean; _sharedSessionBean.putJSPBean(getJSPCode(), this); } else { if (_sharedSessionBean != newSharedSessionBean) { throw new IllegalStateException("SharedSessionBean is not set properly. SharedSessionBean must be the same for all PageBeans within the session"); } } } public SharedSessionBean getSharedSessionBean () { return _sharedSessionBean; } public void setSkipPageOutput (boolean newSipPageOutput) { _skipPageOutput = newSipPageOutput; } public boolean getSkipPageOutput () { return _skipPageOutput; } protected void redirect (String redirectURL) throws java.io.IOException { // skip the page output since we are redirecting setSkipPageOutput(true); _response.sendRedirect(redirectURL); } public void setRequest (HttpServletRequest newRequest) { _request = newRequest; } public void setResponse (HttpServletResponse newResponse) { _response = newResponse; } public void setServlet (Servlet newServlet) { _servlet = newServlet; } } |
public void process() throws java.io.IOException { setSkipPageOutput(false); // by default do not skip page output. Specific bean process // methods can override it. if (getState() == NEW) { setState(FIRSTPASS); beanFirstPassProcess(); } else { resetErrorMsg(); setState(PROC); beanProcess(); } .... |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。