共用JSP部署後測試代碼

來源:互聯網
上載者:User

標籤:tomcat   getremoteaddr   jsp測試網頁   

為了方便,不想修改JSP代碼,所以直接編寫JSP代碼。日後只要複製過去就可以測試伺服器相關資訊。

(說明:本人不會JAVA,第一次編寫JSP,只是測試使用)

效果如下:

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/4B/8F/wKioL1Qu2n-jEFDSAAJIgQM7Fo4516.jpg" title="1.jpg" alt="wKioL1Qu2n-jEFDSAAJIgQM7Fo4516.jpg" />

代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ page contentType="text/html; charset=UTF-8"%>


<%@ page import="java.util.*" %> 

<html>

        <head>

                <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>

                <title>sunday tomcat</title>

                <meta name="Author" content="centos,yum,update" />

                <meta charset="utf-8" />

                <link rel="shortcut icon" href="images/itour.ico" />

        </head>

<body>

<br><br><br>

<% 


  //HttpSession session = request.getSession(true); 


  System.out.println(session.getId());


  //out.println("<br> SESSION ID:" + session.getId()+"<br>");


String serverName = request.getServerName();

int serverPort = request.getServerPort();

%>

<table width="80%" border="1" align="center">

    <tr>

        <th colspan=2>tomcat test by linwangyi</th>

    </tr>

    <tr>

        <td>伺服器IP</td>

        <td><% String serverIP  = request.getLocalAddr();

out.print( serverIP);%></td> 

    </tr>

    <tr>

        <td>伺服器tomcat連接埠</td>

        <td><% int serverPORT = request.getLocalPort();

out.print( serverPORT);%></td> 

    </tr>

<tr>

        <td>訪問主機名稱</td>

        <td><%=serverName%></td>

    </tr>

    <tr>

        <td>訪問連接埠</td>

        <td><%=serverPort%></td>

    </tr>

<tr>

        <td>根目錄絕對路徑</td>

        <td><%out.print( application.getRealPath(request.getRequestURI()) );%> </td>

    </tr>

<tr>

        <td>SESSION ID</td>

        <td><%=session.getId()%></td>

    </tr>


<tr>

        <th colspan=2>用戶端資訊</th>

    </tr>

    <tr>

        <td>用戶端IP</td>

        <td><%

String USERHeader=request.getHeader("x-forwarded-for");

if (USERHeader != null) {

out.print( request.getHeader("x-forwarded-for") );

} else {

out.print( request.getRemoteAddr() );

}

%></td>

    </tr>

    <tr>

        <td>User-Agent資訊</td>

        <td><% String USERAgent  = request.getHeader("User-Agent");

out.print( USERAgent);%></td> 

    </tr>

</table>

</body>

</html>


本文出自 “都市布衣” 部落格,請務必保留此出處http://sunday208.blog.51cto.com/377871/1560552

共用JSP部署後測試代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.