jsp第七周作业

1.教材P78-79 例4-9

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
商品编号A1001,价格8765<a href="0413a.jsp?id=A1001&price=8765">购买</a>
商品编号A1002,价格8765<a href="0413a.jsp?id=A1002&price=98.78">购买</a>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<%
String a =request.getParameter("id");

 

 

 

 

2.教材P97 实验2

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="0413b.jsp" >

输入运算数,选择运算符号<br>
<input name="a">
<select name="b">
<option value="+"><option value="-"><option value="*"><option value="%"></select>
<input name="c">
<input  type="submit">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<%
    String a = request.getParameter("a");
    String b = request.getParameter("b");
    String c = request.getParameter("c");
    
    if(a==null && c==null){
        out.print("输入错误");
    }
    double aa = Double.parseDouble(a);
    double cc = Double.parseDouble(c);
    if("+".equals(request.getParameter("b"))){
        out.print(aa+cc);
    }
    if("-".equals(request.getParameter("b"))){
        out.print(aa-cc);
    }
    if("*".equals(request.getParameter("b"))){
        out.print(aa*cc);
    }
    if("%".equals(request.getParameter("b"))){
        out.print(aa/cc);
    }
%>
</body>
</html>

 

 

 

 


3.制作一个登陆表单,输入账号和密码,如果账号密码相同,跳转到“登录成功”页面,否则跳转到“登录失败”页面。(加上JS非空验证)(选做,加验证码)

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>

</head>
<body>
<form action="0413c.jsp" >
账号<input id="nn" name ="a" type="text">
密码<input id="xx" name ="b" type="text">
<input id="button" type="submit" onclick="return a">
<input type="checkbox" name="vip" value="是否成为会员" checked="checked"/>是否成为会员


</form>

<script type="text/javascript">
        var btn = document.getElementById("button");  
        btn.onclick = function(){
            var nn = document.getElementById("nn");
            var xx = document.getElementById("xx");   
            if(nn.value=="" ||xx.value==""){
                alert("不能为空");  
                            
                return false;
            }
                            
        }
        
    </script>
</body>

</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<%
if(request.getParameter("a").equals(request.getParameter("b"))){
    out.println("登录成功");
    if(request.getParameterValues("vip")!=null){
        out.print("欢迎您注册为会员");
    }
}else{
    out.println("登录失败");
}

%>
</body>
</html>

 

 

 

 

4.在上题的表单中增加一个checkbox,让用户选择“是否注册为会员",如果注册为会员,则在显示时增加文本“欢迎您注册为会员”。

5.在页面1的表单内输人一个数字N,提交,能够在另一个页面打印N个“欢迎”字符串。

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<form action="0413d.jsp">
<input name="a" type="text" >
<input type="submit" value="提交">

</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<%
    int a = Integer.valueOf(request.getParameter("a"));
for(int i = 0 ; i <= a-1 ; i++){
    out.println("欢迎");
}
%>
</body>
</html>

 

 

 

 

6.在页面1中输入账号和密码,进行登录,如果账号和密码相同,则认为成功登录到页面2,在页面2中显示一个文本框输人用户姓名,输人之后提交,在页面3中显示用户的账号和姓名。(转发)request.getRequestDispacher.....forward

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<form action="0413e.jsp" >
账号<input name ="a" type="text">
密码<input name ="b" type="text">
<input  type="submit" value="提交">



</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<%
    Object s =request.getAttribute("a");
    
%>
页面二
<form action="0413f.jsp?a=1" >
姓名<input name ="c" type="text">
<input name="acount" type="hidden" value="<%= s %>">
<input  type="submit" value="提交">



</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<%
if(request.getParameter("a").equals(request.getParameter("b"))){
    request.setAttribute("a", request.getParameter("a"));
    request.getRequestDispatcher("/04130601.jsp").forward(request, response);
}else{
    out.println("登录失败");
}

%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>

姓名:<%= request.getParameter("c")  %>
账号:<%= request.getParameter("acount")%>
</body>
</html>

 

 

 

 

 

posted @ 2022-04-13 15:20  王玉宁325  阅读(44)  评论(0编辑  收藏  举报