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> </th>
<td><input type="submit" value="提交"> <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")+" "%>
<% }
%>
</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>