实现跳转的jsp小例子

 

<%@page import="java.io.UnsupportedEncodingException"%>
<%@ page language="java" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>学员注册</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>

<body>

    <div align="center">
        <form name="" method="post" action="/jsp-day2/mvc/do.jsp">
            <table border="0" align="center">
                <tr>
                    <td>用户名:</td>
                    <td><input type="text" name="name"></td>
                </tr>
                <tr>
                    <td height="19">密码:</td>
                    <td height="19"><input type="password" name="pwd"></td>
                </tr>
                <tr>
                    <td colspan="2" align="center"><input type="submit"
                        name="Submit" value="提交"> <input type="reset" name="Reset"
                        value="取消"></td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>
<%@page import="java.io.UnsupportedEncodingException"%>
<%@ page language="java" pageEncoding="UTF-8"%>

<%
    String name = request.getParameter("name");
    String pwd = request.getParameter("pwd");
    if ("1".equals(name) && "1".equals(pwd)) {
        //跳转到最终页面
        //1转发
        request.setAttribute("usname", name);
        //转发不需要项目名称
        request.getRequestDispatcher("/mvc/z2.jsp").forward(request, response);
        //2重定向
        //response.sendRedirect("/jsp-day2/mvc/z2.jsp");
    }
%>
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<title>Hello!</title>

</head>

<body>
    欢迎来到HtF-8的购物商城<%=request.getAttribute("usname")%>>
</body>
</html>

 

 网页打开方式:

 

 

实现结果:

 

posted @ 2018-07-23 12:18  H丶  阅读(201)  评论(0编辑  收藏  举报