tomcat 输入IP和端口跳转到自定的路径

在ROOT应用的index.jsp中加入下面这段代码即可!


<%@ page import="java.net.HttpURLConnection, java.net.URL, javax.net.ssl.*, java.security.*" %>

<%

 String requestedURL = request.getRequestURL().toString();
 int responseCode = -1;
 String fileName = null;
 URL url = new URL(requestedURL+"/admin");//modifyinggggg
 if(request.isSecure())
 {
  try {
   SSLContext sc = SSLContext.getInstance("SSL");
   sc.init(null, null, new java.security.SecureRandom());
   HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
   // Create a HostNameVerifier to verify nothing ...
   HostnameVerifier hv = new HostnameVerifier() {
      public boolean verify(String urlHostName, SSLSession session) {
         return true;
   }
   };
   HttpsURLConnection.setDefaultHostnameVerifier(hv);
  } catch (Exception e) {
  }

  HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
  
  try
  {
   con.connect();
   responseCode = con.getResponseCode();
  } 
  catch(Exception e)
  {
   // do nothing here as the exception can occur even when the functionality is proper.
  }
 }

    else
 {
  HttpURLConnection con = (HttpURLConnection) url.openConnection();  
  try
  {
   con.connect();
   responseCode = con.getResponseCode();
  } 
  catch(Exception e)
  {
   // do nothing here as the exception can occur even when the functionality is proper.
  }
 }
 if( responseCode >= 400 )//logggg
 {
  fileName = "/default.jsp";
 }
 else
 {

  //设定指定的路径
  fileName = "/axis2";  
 }
 response.sendRedirect(fileName);
%>

你可能感兴趣的:(java,tomcat,jsp,.net,Security)