servlet搭建
来源:互联网 发布:深圳app软件开发公司 编辑:程序博客网 时间:2024/06/03 21:53
1 前端页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登录</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="http://localhost:8080/loginServlet/login" method="post" accept-charset="utf-8">
用户:<input type="text" name="username" /><br>
密码:<input type="password" name="password" /><br>
<input type="submit" value="登录" />
</form>
</body>
</html>
2 映射关系
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>
3 action处理
//引入所需要的包
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginServlet extends HttpServlet {
//重写doGet方法
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String username = request.getParameter("username");
PrintWriter out=response.getWriter();
out.println(username);
System.out.println(username);
}
//重写doPost方法
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException {
doGet(request, response);
}
}
- Servlet搭建
- servlet搭建
- 搭建eclipse servlet环境
- HelloWorld_Servlet-servlet框架搭建
- EclipseIDEforJavaEE搭建servlet
- Servlet开发环境搭建
- windows Servlet 环境搭建
- JSP和Servlet环境搭建
- servlet在eclipse中搭建
- spring框架搭建---servlet,jdbc
- 搭建简单的servlet&MySQL
- Eclipse JSP/Servlet 环境搭建
- Servlet+Tomcat搭建Http服务
- Servlet详解及搭建教程
- Eclipse IDE for Java EE 搭建 servlet
- Servlet & Jsp 项目搭建问题汇总
- Tomcat手工搭建Jsp和Servlet程序
- 自己动手搭建Tomcat下的Servlet
- tp框架的两种模式
- httpclient连接超时时间设置
- cookie
- oclint规则
- [leetcode][SQL]181. Employees Earning More Than Their Managers
- servlet搭建
- spring集成 JedisCluster 联接 redis3.0 集群
- instanceof, isinstance,isAssignableFrom的区别
- 33. Search in Rotated Sorted Array
- java enum(枚举)使用详解 + 总结
- qt鼠标事件总结
- 分布式事务解决方案(一)
- Coordinated Universal Time (UTC)与系统时间的误差
- Linux网络编程 - TCP Socket 简单练习:select同时监测多个描述符