JSP用MVC架构注册登录的例子

来源:蓝色理想 作者:信心索 2007-12-03 出处:pcdog.com

dos  java  stp  xml  数据库  
上一页 1 2 3 4 下一页 

  自定义标签类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">请输入用户名和密码,或者创建一个新用户!</font>
<%@ include file="/login_form.jsp" %>
<hr>
<a href="<%=response.encodeURL("newAccount.jsp")%>">创建一个新用户 </a>
</body>
</html>

上一页 1 2 3 4 下一页 
上一篇:JSP 循序渐进教程
下一篇:Linux平台jsp环境搭建(Tomcat4+jdk+postgreS)