注册 | 登录 | 设为首页 | 加入收藏
您当前的位置:飞翔学院-IT中国 → 编程开发JSP → 文章内容

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

作者:佚名 来源:不详 发布时间:2007-11-30 0:08:22

  自定义标签类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]  下一页


  • 打印文档
  • 推荐好友
  • 返回顶部
  • 增大字体
  • 减少字体
关于本站 | 工作机会 | 合作网站 | 广告服务 | 市场合作| 联系我们 | 抽奖活动
版权所有: 武汉威俊科技有限公司 Copyright 2005-2007 www.ITCNW.COM All rights reserved