MyEclipse web 简单 网站项目 创建

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(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>

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值