我是新來的JSP,我試圖寫下面的代碼:簡單的JSP應用
<%@ page import="java.io.*" %>
<%@ page import="com.wipro.assignment2.exceptions.UploadFileNotFoundException" %>
<%
String requestPath=request.getParameter("file1");
System.out.println("I am printing before SUBMIT button click");
if(requestPath!=null)
{
File f=new File(requestPath.trim());
System.out.println("Path given to upload : "+requestPath);
if(!f.exists())
{
System.out.println("one");
try
{
throw new UploadFileNotFoundException("The file trying to upload is not presnt in its path !!!");
}
catch(UploadFileNotFoundException filenotfound)
{
throw filenotfound;
}
}
}
%>
<html>
<body>
<form name="form1" method="post" enctype="multipart/form-data">
<table align="right">
<tr>
<td><A href="index.html">HOME</A></td>
</tr>
</table>
</table>
<table>
<tr>
<td>Select File </td>
<td> <input type="file" name="file1"> </td>
<tr>
<td><input type="submit" value="Upload"></td>
</tr>
</table>
</form>
</body>
</html>
在這裏,一旦這個JSP頁面加載上面的代碼,被點擊提交按鈕之前,JSP開始運行,如果我按下提交按鈕,請求不會傳遞給上面的JSP。請告訴我它是如何工作的。
謝謝唐,我會嘗試 – i2ijeya 2009-09-15 14:59:59
我剛接觸JSP唐..所以,請你說我們爲什麼要使用標籤庫。 – i2ijeya 2009-09-15 15:33:24