Form Processing Problem

Form Processing Problem

I am trying to create a Circular Page. This is the Code where the circular is updated and asks for Circular Reference number and date.

<%@ page import="java.io.*" %>
<%
        //to get the content type information from JSP Request Header
        String contentType = request.getContentType();
        //here we are checking the content type is not equal to Null and
 //as well as the passed data from mulitpart/form-data is greater than or
 //equal to 0
        if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
                DataInputStream in = new DataInputStream(request.getInputStream());
                //we are taking the length of Content type data
                int formDataLength = request.getContentLength();
                byte dataBytes[] = new byte[formDataLength];
                int byteRead = 0;
                int totalBytesRead = 0;
                //this loop converting the uploaded file into byte code
                while (totalBytesRead < formDataLength) {
                        byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
                        totalBytesRead += byteRead;
                        }
                                        String file = new String(dataBytes);
                //for saving the file name
                String saveFile = file.substring(file.indexOf("filename=\"") + 10);
                saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
                saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));

                File f=new File("C:/Program Files/Apache Software Foundation/Apache Tomcat 7.0.34/bin/UploadedFiles/"+saveFile); //the changed code->1  

                int lastIndex = contentType.lastIndexOf("=");
                String boundary = contentType.substring(lastIndex + 1,contentType.length());
                int pos;
                //extracting the index of file 
                pos = file.indexOf("filename=\"");
                pos = file.indexOf("\n", pos) + 1;
                pos = file.indexOf("\n", pos) + 1;
                pos = file.indexOf("\n", pos) + 1;
                int boundaryLocation = file.indexOf(boundary, pos) - 4;
                int startPos = ((file.substring(0, pos)).getBytes()).length;
                int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
                // creating a new file with the same name and writing the content in new file

                FileOutputStream fileOut = new FileOutputStream(f);

                //FileOutputStream fileOut = new FileOutputStream(saveFile);
                fileOut.write(dataBytes, startPos, (endPos - startPos));
                fileOut.flush();
                fileOut.close();
                                %><Br><table border="2"><tr><td><b>You have successfully  upload the file by the name of:</b>
                                            <!--<br><a href="viewFiles.jsp">View Files</a>-->
                                            **<br><br><br><form action="viewFiles.jsp" method="POST">
Circular Reference#: <input type="text" name="first_name">
<br />
Circular Date: <input type="text" name="last_name" />
<input type="submit" value="Submit" />
</form>
                <% out.println(saveFile); %></td></tr></table> 
                <%
                }
%>

and below is the code where it will view the inputs taken like Circular Reference and date viewFiles.jsp

<%@ page import="java.io.*"%>
<html>
<table>
<tr><th>Circular Name</th><th>Download File</th>
<%
File f = new File("C:/Program Files/Apache Software Foundation/Apache Tomcat 7.0.34/bin/UploadedFiles/");
        File[] files = f.listFiles();
        for(int i=0;i<files.length;i++){
            String name=files[i].getName();
            String path=files[i].getPath();
%>
<tr><td><%= request.getParameter("first_name")%></td><td><%= request.getParameter("last_name")%></td><td><%=name%></td><td><a href="download.jsp?f=<%=path%>">Download File</a></td></tr>
     <%
        }
%>
</table>
</html>

The problem while displaying according to the code.. If we upload 3 files for all the files it will display the same circular date and reference as the variable is not unique for each inputs taken. Kindly help me, to take unique inputs from forms and the inputs will be saved when I open viewFiles.jsp. So that I can enter new Circular Reference and Date for other files uploaded and save it, so that it can be displayed in columns like

Circular reference Circular Date Files Download Files

View Answers

Ads









Related Tutorials/Questions & Answers:
Form Processing Problem
Form Processing Problem  I am trying to create a Circular Page... to Null and //as well as the passed data from mulitpart/form-data is greater...; (contentType.indexOf("multipart/form-data") >= 0)) { DataInputStream
PROBLEM IN FORM VALIDTION
PROBLEM IN FORM VALIDTION  i applied validation IN THIS JSP PAGE.if i... the PROBLEM is that after i press OK on validation prompt,the page goes...; } </script> </head> <body> <form name="form" method="post
Advertisements
PHP Sticky form problem
PHP Sticky form problem  I have done the full coding of a sticky form.... Please see my coding below...and advice me what is the problem, and what...;/head> <body> <h1>Simple Calculator</h1> <form action
PHP Sticky form problem
PHP Sticky form problem  I have done the full coding of a sticky form.... Please see my coding below...and advice me what is the problem, and what...> <form action="simple_calculator.php" method="post"> <p>Number 1
Problem in enctype="multipart/form-data" in JSP
Problem in enctype="multipart/form-data" in JSP  im using a page... the file itself when i click the submit button. im using enctype="multipart/form-data" in this form. i also using the commons-fileupload-1.2.2.jar file for getting
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE.... 1)register.jsp <html> <form method="post" action="insert.jsp"> <
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE.... 1)register.jsp <html> <form method="post" action="insert.jsp"> <
data processing is
data processing is   data processing is   Data processing is associated with commercial work. Data processing is also referred as Information System. Data processing is basically used for analyzing, processing
jsp form
jsp form  hi sir, one got one got in jsp form after entering the data into the form the data is not saving in the database i will send you code of two forms if dnt understand my problem
image Processing
image Processing   BCIF Image Compresssion Algorithm s alossless image Compression algorithm ,Pleas Help Me weather it can support only 24 bit bmp images
Problem in enctype=
Problem in enctype=  im using a page which is in JSP. i have some... the submit button. im using enctype="multipart/form-data" in this form. i also using.... but the problem is the uploaded file is not stored in the prefered folder. i printed
problem related to onSubmit() method
problem related to onSubmit() method  Hello, I am developing application.when i submit form at that time formBacking() method is call...Instead of that onSubmit() should have to call .... please help me
problem in onlinetest...
problem in onlinetest...  hi, my code getting the problem is ,when user leave a question then the server puts error... pls help me
PHP form
PHP form  Hi Sir/Madam, I am developing an attendance form using php... am adding one textfield to enter the Attendance... The problem is I am... form and update them to respective coloumn... Please any one help mo out please
uploading problem
;font size="+3" color="white"> <TABLE> <tr><td><form...; <TABLE> <TR><TD><form name="form2" action...(); } } } } %> my problem...: firstly
jsp problem
jsp problem  problem:::::::: On JSP form ,when i insert data in text... and get assign to other field on that form........ when data is assign to other field on that form at that time firstly inserted data is not present on that form
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table... in advance.   1)form.html: <html> <form method="post
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table... in advance.   1)form.html: <html> <form method="post
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table... in advance.   1)form.html: <html> <form method="post
logout problem
me out of this... the problem is -- when i logout , the user goes... he has come from .. please get me out of this problem thanks.   Use...;/head> <br> <body Bgcolor ="#0099cc"><hr><hr> <form
ModuleNotFoundError: No module named 'processing'
ModuleNotFoundError: No module named 'processing'  Hi, My Python... 'processing' How to remove the ModuleNotFoundError: No module named 'processing' error? Thanks   Hi, In your python environment you
request processing in servlets
request processing in servlets  how request processing is done in servlets and jsp   Please visit the following links: JSP Tutorials Servlet Tutorials Here, you will find several examples of processing request
javascript problem
javascript problem  hi guys My problem is that I am using radio button for yes or no but i want to do that if I press yes button then enter... enter please help me this problem
Processing Sequence of DispatcherServlet
In this section, you will get to know about the processing sequence of DispatcherServlet
jdbc problem
jdbc problem   hi my name is mohit...i am making a project in java... to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings
problem on strings
problem on strings  in string1 "123456 ABC DEF...",IN string2 "raveen". iwant to add string2 after 123456 in the first string based on index number.i need logic for this with out using StringBuffer concept. Thanks in advanace
Problem with loginbean.jsp
Problem with loginbean.jsp  http://www.roseindia.net/jsp/loginbean.shtml - I am getting an error in loginbean.jsp.There is some error regarding .What is hello in this? Also in this example how
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
Problem with cookies
Problem with cookies  Hello All, i need jsp code for RememberMe module of login. i am facing problem with cookies. so please if any one could guide me please help and provide mme the exact code.   Please visit
problem with package
problem with package  Dear sir, i have created one java file with package com.net; and i compiled the program.it showing the .class file in " net" folder.The problem is i want to use that .class file in some other

Ads