《web应用技术》第一次课后练习

1、下载软件并安装:JDK、TOMCAT、IDEA

2、用记事本写出jsp文件并放入tomcat相关目录运行

3、在IDEA中新建java web项目并配置tomcat运行jsp文件 

4、自学IDEA的各种使用技巧 

 

5、JSP编程练习

(1)用JSP实现用户获取用户输入的操作。 

input.jsp

<%--
  Created by IntelliJ IDEA.
  User: 19392
  Date: 2024/4/2
  Time: 20:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>输入</title>
    <style type="text/css">
        table,th,td{border: 1px solid silver;}
    </style>
</head>
<body>
    <form action="output.jsp" method="post">
            <table style="border-spacing: 10px;">
            <tr>
                <th>姓名:</th>
                <td><input type="text" name="name"/></td>
            </tr>
            <tr>
                <th>性别:</th>
                <td>
                    <input name="sex" type="radio" value="男"/>男
                    <input name="sex" type="radio" value="女"/>女
                </td>
            </tr>
            <tr>
                <th>爱好:</th>
                <td>
                    <div style="width: 400px">
                    <input name="like" type="checkbox" value="篮球"/>篮球
                    <input name="like" type="checkbox" value="旅游"/>旅游
                    <input name="like" type="checkbox" value="音乐"/>音乐
                    <input name="like" type="checkbox" value="摄影"/>摄影
                    </div>
                </td>
            </tr>
            <tr>
                <th>E-mail:</th>
                <td><input type="text" name="key"></td>
            </tr>
            <tr>
                <th>&nbsp;</th>
                <td><input type="submit" value="提交">&nbsp;&nbsp;<input type="reset" value="全部重写"></td>
            </tr>
            </table>
    </form>
</body>
</html>

output.jsp

<%@ page import="java.nio.charset.StandardCharsets" %><%--
  Created by IntelliJ IDEA.
  User: 19392
  Date: 2024/4/2
  Time: 20:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <title>输出</title>
    <style type="text/css">
        table,th,td{border: 1px solid silver;}
    </style>
</head>
<body>
<table style="border-spacing: 10px;">
    <caption>用户输入的信息</caption>
    <tr>
        <th>姓名:</th>
        <td><%=new String(request.getParameter("name").getBytes("ISO8859_1"),"UTF-8")%></td>
    </tr>
    <tr>
        <th>性别:</th>
        <td><%=new String(request.getParameter("sex").getBytes("ISO8859_1"),"UTF-8")%></td>
    </tr>
    <tr>
        <th>爱好:</th>
        <td>
            <div style="width: 400px">
                <%
                    String[] like =request.getParameterValues("like");
                    for(int i=0;i< like.length;i++){
                %>
                        <%= new String(like[i].getBytes("ISO8859_1"),"UTF-8")+"&nbsp;&nbsp;"%>
                <%   }
                %>
            </div>
        </td>
    </tr>
    <tr>
        <th>E-mail:</th>
        <td><%=new String(request.getParameter("key").getBytes("ISO8859_1"),"UTF-8")%></td>
    </tr>
</table>
</body>
</html>

(2) 用JSP实现用户登录验证的功能

 

 

 

<%--
  Created by IntelliJ IDEA.
  User: 19392
  Date: 2024/4/9
  Time: 22:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String str = request.getParameter("username");
    String pwd = request.getParameter("pwd");
    if(null != str){
        if(str.equals("tom") && pwd.equals("abcd")){
            out.println("您好,tom!");
        }else{
            out.println("您输入的账号密码有误,请重新输入!");
        }
    }
%>
<html>
<head>
    <title>登录界面</title>
</head>
<body>
<form action="log.jsp" method="post">
    账号:<input type="text" name="username"/> <br>
    密码:<input type="password" name="pwd"/> <br>
    <input type="submit" value="登录" />
</form>
</body>
</html>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值