赞
踩
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-v7T4HjXh-1664173167415)(//img-blog.csdn.net/20180321111039363?watermark/2/text/Ly9ibG9nLmNzZG4ubmV0L3gxNDc5NDUyOTk0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)]
web网站后台程序 简单使用
package edu.servlets.test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.*;
public class test extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String name = req.getParameter("user");
name = new String(name.getBytes("ISO-8859-1"),"UTF-8");
System.out.println("get 请求!");
System.out.println("名字:"+name);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
String name = req.getParameter("user");
System.out.println("post请求!");
//响应式客户端
//设置响应类型 text/html 网页 charset
resp.setContentType("text/html;charset=utf-8");
//获得字符输出的对象
PrintWriter out = resp.getWriter();
//输出网页内容
out.println("<DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EM\">");
out.println("<HTML>");
out.println("<HEAD><TITLE>测试响应</TITLE><meta http-equiv='content-type' content='text/html;charset=UTF-8'></HEAD>");
out.println("<BODY>");
out.println("<h1>欢迎老傻逼回家!"+name+"<h1>");
out.println("</BODY>");
out.println("</HTML>");
out.flush();
out.close();
System.out.println("POST的数据:"+name);
}
}
客服端简单 处理
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>index.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body >
<form method="post" action="test">
<input type="text" name="user"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
**xml网站简单配置 servlet 简单配置路径 **
<?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>test</servlet-name>
<servlet-class>edu.servlets.test.test</servlet-class>
</servlet>
<!-- 映射路径 -->
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。