To mrjmukesh thanx its wkin 4me need more help
the code is wking fine actually my application :Uploads the file and stores it on d:\ using MultiRequest class .so now any type of file is getting stored .Although i am getting an alert but the file still gets stored :
Do go thru the code thanku 4 all th help
JSP
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="netui-tags-databinding.tld" prefix="netui-data"%>
<%@ taglib uri="netui-tags-html.tld" prefix="netui"%>
<%@ taglib uri="netui-tags-template.tld" prefix="netui-template"%>
<netui:html>
<head>
<title>
Web Application Page
</title>
<script language="JavaScript">
function checkFileExtension(parafilevalue)
{
var file=parafilevalue.split('.');
validType=false;
if(file.length<2)
{
return false;
}
var fileext=file[1].toLowerCase();
if(fileext=='xml')
{
validType=true;
}
return validType
}
function validateForm()
{
if(!checkFileExtension(document.myForm.myFile1.val ue))
{
alert('Upload a file with extension xml');
return false;
}
return document.myForm.Submit();
}
</script>
</head>
<body>
<FORM NAME="myForm"
ACTION="http://localhost:7008/IntgAppWeb/fwdservlet"
ENCTYPE="multipart/form-data"
METHOD="post">
<INPUT type="file" name="myFile1" accept="text/xml" >
<INPUT TYPE="submit" VALUE="Upload File" onclick="validateForm()">
</FORM>
</body>
</netui:html>
SERVLET THATS BEING CALLED (STORES FILE )
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import com.oreilly.servlet.MultipartRequest;
public class fwdservlet extends HttpServlet
{
public void init(ServletConfig config)throws ServletException
{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws
ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html><head><title>File Stored!</title></head>");
out.println("<body><h1>File Stored!</h1></body></html>");
MultipartRequest multi = new MultipartRequest(request,"d:\\");
}
}
|