自定義標(biāo)簽類GetRequestParameterTag.java package tags;
import javax.servlet.ServletRequest; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.TagSupport;
public class GetRequestParameterTag extends TagSupport { private String property;
public void setProperty(String property){ this.property = property; } public int doStartTag() throws JspException { ServletRequest reg = pageContext.getRequest(); String value = reg.getParameter(property);
try{ pageContext.getOut().print(value == null ? "":value); }catch(java.io.IOException e){ throw new JspException(e.getMessage()); } return SKIP_BODY; } }
登陸成功welcome.jsp <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>Welcome Page</title> </head> <body> <jsp:userBean id="user" scope="session" class="beans.User"/> <!--也可以 <% User user = (User)session.getAttribute("user"); %> --> 歡迎你:<font color=red><%=user.getUserName()%></font> </body> </html>
登陸失敗loginFailed.jsp <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>Login Failed</title> </head>
<body> <font color="#993366">請輸入用戶名和密碼,或者創(chuàng)建一個新用戶!</font> <%@ include file="/login_form.jsp" %> <hr> <a href="<%=response.encodeURL("newAccount.jsp")%>">創(chuàng)建一個新用戶 </a> </body> </html>
出處:藍(lán)色理想
責(zé)任編輯:帥青蛙
上一頁 用MVC架構(gòu)簡單的注冊、登錄例子 [2] 下一頁 用MVC架構(gòu)簡單的注冊、登錄例子 [4]
◎進(jìn)入論壇網(wǎng)絡(luò)編程版塊參加討論
|