1.form表单值的获取:
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*" pageEncoding="GB18030"%> <html> <head> <title>表单练习</title> </head> <body> <form action="check2.jsp" method="post"> <ul style="list-style: none"> <li><label> 学校名称: <input type="text"name="name"> </label> </li> <li> <label> 所在地区: <select name="location"> <option value="湖北">湖北</option> <option value="青海">青海</option> <option value="辽宁">辽宁</option> </select> </label> </li> <li> <label> 年级: <input type="radio" name="grade" value="大一">大一 <input type="radio" name="grade" value="大二">大二 <input type="radio" name="grade" value="大三">大三 <input type="radio" name="grade" value="大四">大四 </label> </li> <li> <label> 所在专业: <input type="text" name="m"> </label> </li> <li> <label> 兴趣爱好: <input type="checkbox" name="habit" value="唱歌">唱歌 <input type="checkbox" name="habit" value="跳舞">跳舞 <input type="checkbox" name="habit" value="听歌">听歌 </label> </li> <li> <input type="submit"value="submit"> <input type="reset" value="reset"> </li> </ul> </form> </body> </html>
-->
2.用request对象获取表单元素
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*" pageEncoding="GB18030"%> <%@ page import="java.nio.charset.StandardCharsets" %> <html> <head> <title>表单提交</title> </head> <body> <ul style="list-style: none"> <li> 学校名称: <% String name=new String(request.getParameter("name").getBytes("ISO8859_1"),"UTF-8"); out.println(name); %> </li> <li> 所在地区: <% String location=new String(request.getParameter("location").getBytes("ISO8859_1"),"UTF-8"); out.println(location); %> </li> <li> 年级: <% String grade=new String(request.getParameter("grade").getBytes("ISO8859_1"),"UTF-8"); out.println(grade); %> </li> <li> 所在专业: <% String major=new String(request.getParameter("m").getBytes("ISO8859_1"),"UTF-8"); out.println(major); %> </li> <li> 兴趣爱好: <% String [] habit= request.getParameterValues("habit"); for (int i=0;i<habit.length;i++){ String habitx=new String(habit[i].getBytes("ISO8859_1"),"UTF-8")+" "; out.println(habitx); } %> </li> </ul> </body> </html>
3.mysql的环境变量配置和tomcat相同
4.安装navcat
5.新建maven项目,导入驱动jar包