准备两台Tomcat,当其中一台Tomcat挂掉(服务器宕机),便找另一台服务器继续运行
Nginx解决跨域问题,实现方案: www.a.com:8080/a www.b.com:8081/b
如果在b工程的页面直接发送ajax请求a时会发生跨域问题,那么解决方案为:将A和B同时代理到Nginx,由Nginx做请求路由,直接在B工程页面中直接访问Nginx即可
package com.a;
import Javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException;
@WebServlet("/NginxServlet") public class NginxServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1、接收数据 String username = request.getParameter("username"); System.out.println("接收的数据:"+username);
//2、响应结果 response.getWriter().write("success"); }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } }
4、index.jsp
<%-- Created by IntelliJ IDEA. User: zheng Date: 2020/2/10 Time: 15:01 To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head> <title>Nginx解决跨域问题</title> <script type="text/javascript" src="https://www.linuxidc.com/Linux/2020-02/js/jquery-1.8.3.min.js"></script> <script> .ajax({ url:"http://www.znzn.com/A/NginxServlet?username="+