首页 > 代码库 > 共享JSP部署后测试代码

共享JSP部署后测试代码

为了方便,不想修改JSP代码,所以直接编写JSP代码。日后只要复制过去就可以测试服务器相关信息。

(说明:本人不会JAVA,第一次编写JSP,只是测试使用)

效果如下:

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="http://www.mamicode.com/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部署后测试代码