• Nginx+Tomcat部署Servlet测试


    一、服务端代码 MyEclipse新建Servlet
    #Name:StringContentServlet
    #Servlet/JSPMappingUrl:/StringContentServlet.do
    package com.jimmy.Servlets;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.Writer;;
    
    public class StringContentServlet extends HttpServlet {
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {        
            String username = request.getParameter("UserName");
            String password = request.getParameter("PassWord");            
            System.out.println(username + " " + password);
            
            Writer out = response.getWriter();        
            if(username != null || password !=null)
            {
                out.write("true001");
            }
            else
            {
                out.write("false001");
            }        
        }
    }
     
    二、Unity客户端代码
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    
    public class Login : MonoBehaviour
    {
        public InputField Username;
        public InputField Password;
        private string url = "http://101.200.55.192:8080/UnityToJSP/StringContentServlet.do?";
    
        public void LoginButtonOnClick()
        {
            string parameter = "";
            parameter += "UserName=" + Username.text + "&";
            parameter += "PassWord=" + Password.text;
            StartCoroutine(login(url + parameter));
        }
    
        IEnumerator login(string path)
        {
            WWW www = new WWW(path);
            yield return www;
            if (www.error != null)
            {
                Debug.Log(www.error);
            }
            else
            {
                if (www.text.Equals("true001"))
                {
                    print("Login Success!");
                }
                else
                {
                    print("Login Fail....");
                }
            }
        }
    }

    三、Liunx部署,把tomcat端口为8081

    cd apache-tomcat-7.0.75

    gedit conf/server.xml
    四、配置Nginx
    nginx -t
    gedit /etc/nginx/nginx.conf
    nginx -s reload
    http {
    upstream tomcat_server
    {     
           server localhost:8081;
    }
    server
     {
        listen          8080;   
        server_name     localhost:8080; 
    
        if (-d $request_filename)
        {   
            rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
        }
    
        location ~ .(jsp|jspx|do)?$
        {   
            proxy_pass http://tomcat_server;
            proxy_set_header   Host    $host;     
            proxy_set_header   X-Real-IP   $remote_addr;     
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;   
        }
    }
    五、登陆测试
  • 相关阅读:
    chrome——关于chrome浏览器的奇葩问题
    vscode——配置终端集成bash和cmd
    AndroidStudio——Android SDK
    Navicat——如何导出所有的查询数据
    mpvue——实现点击数组内的某一元素进行置顶(排序第一)操作
    TP5.x——开启跨域访问
    TP5.x——聊天列表查询
    MarkDowm——语法篇
    写一个整数四则运算的解析器——语法分析部分
    写一个整数四则运算的解析器——词法分析部分
  • 原文地址:https://www.cnblogs.com/JimmyCode/p/6727126.html
Copyright © 2020-2023  润新知