|
|
package lightbox;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*;
import java.io.*;
import java.text.*;
public class appTest {
// *****************************************************
// 物理パス取得
// *****************************************************
public String getRealPath( ServletContext app, String strUrl ) {
String strPath = null;
strPath = app.getRealPath( strUrl );
return strPath;
}
}
| |
|
appTest.bat
|
javac
-classpath
"..\;C:\Tomcat5.5\common\lib\servlet-api.jar;C:\Tomcat5.5\common\lib\jsp-api.jar"
appTest.java
| |
|
|
|
sample_04.jsp
|
<%@ page
language="java"
import="java.io.*"
import="java.text.*"
import="java.util.*"
import="lightbox.*"
contentType="text/html;charset=shift_jis" %>
<%
// *********************************************************
// 物理パス取得
// *********************************************************
appTest myApp = new appTest();
String strPath = myApp.getRealPath( application, "" );
%>
<HTML>
<BODY>
物理パス = <%= strPath %>
</BODY>
</HTML>
| |
|
|
|
sample_05.jsp
|
<%@ page
language="java"
import="java.io.*"
import="java.text.*"
import="java.util.*"
contentType="text/html;charset=shift_jis" %>
<jsp:useBean id="myApp" scope="session" class="lightbox.appTest" />
<%
// *********************************************************
// 物理パス取得
// *********************************************************
String strPath = myApp.getRealPath( application, "" );
%>
<HTML>
<BODY>
物理パス = <%= strPath %>
</BODY>
</HTML>
| |
|
|
|
|
<%! 〜 %> で定義されています
※ このメソッドは、定義されたページのみで使用できます
| |
|
sample_06.jsp
|
<%@ page
language="java"
import="java.io.*"
import="java.text.*"
import="java.util.*"
contentType="text/html;charset=shift_jis" %>
<%!
// *********************************************************
// 物理パス取得
// *********************************************************
public String getRealPath( ServletContext app, String strUrl ) {
String strPath = null;
strPath = app.getRealPath( strUrl );
return strPath;
}
%>
<%
String strPath = getRealPath( application, "" );
%>
<HTML>
<BODY>
物理パス = <%= strPath %>
</BODY>
</HTML>
| |
|
|
|
jsp_func.jsp
|
<%@ page
language="java"
import="java.io.*"
import="java.text.*"
import="java.util.*"
contentType="text/html;charset=shift_jis" %>
<%
String strTypeName = null;
String strParam1 = null;
strTypeName = (String)request.getAttribute( "typeName" );
if ( strTypeName == null ) {
return;
}
if ( strTypeName.equals( "getRealPath" ) ) {
strParam1 = (String)request.getAttribute( "param1" );
request.setAttribute(
"getRealPath",
application.getRealPath( strParam1 )
);
}
%>
| |
|
sample_06_include.jsp
|
<%@ page
language="java"
import="java.io.*"
import="java.text.*"
import="java.util.*"
contentType="text/html;charset=shift_jis" %>
<%
request.setAttribute( "typeName", "getRealPath" );
request.setAttribute( "param1", "" );
%>
<jsp:include page="jsp_func.jsp" flush="true" />
<%
String strPath = (String)request.getAttribute( "getRealPath" );
%>
<HTML>
<BODY>
物理パス = <%= strPath %>
</BODY>
</HTML>
| |
|
|
|