客户端访问服务端:
1.创建DynamicWebProject 工程
2.在webContent目录下,创建login.html(index.html或者default.html会默认加载)
<form action=”服务器的serverlet路径”> </form>
3.在Servlet中的doGet()或者doPost()中编写代码
A.设置编码 //request response
Requeset.setCharacterEncoding(“utf-8”);
response.setCharacterEncoding(“utf-8”);
Response.setContentType(“text/html;charset=utf-8”);
B.获取客户端传过来的数据
String str=request.getParameter(“参数名”);
C.查询数据库,判断
D.根据查询结果给客户端响应
PrintWriter out=response.getWriter();
Out.println(“响应内容”);
//响应跳转
response.sendRedirect(“success.html”);
4.启动tomcat部署程序
5.在浏览器的输入地址访问
http://IP地址:8080/项目名/login.html(要访问页面路径)
注意:具体在页面action后面配置的服务器地址,可在web.xml中配置映射。