简易服务器搭建(get post方法)
2016-02-05 17:28
513 查看
使用MyEclice10+TomCat7.x进行的试验
LoginServlet类
jsp测试页面
web.xml文件配置
LoginServlet类
package com.jacky.login; import java.io.IOException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String name = request.getParameter("username"); // 获取用户名 String pwd = request.getParameter("password"); // 获取密码 System.out.println("username:" + new String(name.getBytes("iso-8859-1"), "utf-8")); System.out.println("password:" + pwd); if ("abc".equals(name) && "123".equals(pwd)) { response.getOutputStream().write("sucess".getBytes()); } else { response.getOutputStream().write("login fail".getBytes()); } } @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("post方式提交数据"); doGet(request, response); } }
jsp测试页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html;charset=utf-8"> <title>login</title> </head> <body> <form action="/login/LoginServlet"> <br>get<br> <br>ID<br><input type ="text" name="username"> <br>KEY<br><input type ="password" name="password"> <br> <input type="submit"> </form> <form action="/login/LoginServlet" method="post"> <br>post<br> <br>ID<br><input type ="text" name="username"> <br>KEY<br><input type ="password" name="password"> <br> <input type="submit"> </form> </body> </html>
web.xml文件配置
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>LoginServlet</servlet-name> <servlet-class>com.jacky.login.LoginServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginServlet</servlet-name> <url-pattern>/LoginServlet</url-pattern> </servlet-mapping> </web-app>
相关文章推荐
- java-模拟tomcat服务器
- 小心服务器内存居高不下的元凶--WebAPI服务
- i-jetty环境搭配与编译
- 实现单Tomcat多Server配置
- 生产环境下的Tomcat配置
- 运维入门
- Linux部署Tomcat服务器
- jenkins------结合maven将svn项目自动部署到tomcat下
- 如何搞定tomcat这只喵~
- 利用开源软件打造自己的全功能远程工具
- Linux5.9无人值守安装
- 数据中心和云未来的十二大趋势
- 用vsftp快速搭建ftp服务器
- Linux快速构建apache web服务器
- 服务器监控策略浅谈
- 如何降低服务器采购成本 原理分析
- 建议的服务器分区办法
- 服务器托管六大优势分析