Form Processing Problem

Ads
 

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
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
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
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
Processing Sequence of DispatcherServlet
In this section, you will get to know about the processing sequence of DispatcherServlet
The product of data processing is
The product of data processing is   The product of data processing is 1. Data 2. Information 3. Software 4. Computer 5. All of the above   Answer: 3. Software
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
text processing program
text processing program  how can i compare letter by letter? what i was trying to do is a program that can define what is root word,prefix and suffix. plz help
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
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
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
uploading problem
;font size="+3" color="white"> <TABLE> <tr><td><form...; <TABLE> <TR><TD><form name="form2" action...(); } } } } %> my problem...: firstly
image processing in java
image processing in java  public class testing { static BufferedImage image; public static void main(String[] args) throws IOException { ArrayList<Integer> l1=new ArrayList<Integer>(); ArrayList<Integer>
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
ModuleNotFoundError: No module named 'calysto_processing'
ModuleNotFoundError: No module named 'calysto_processing'  Hi, My... named 'calysto_processing' How to remove the ModuleNotFoundError: No module named 'calysto_processing' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'datapunt-processing'
ModuleNotFoundError: No module named 'datapunt-processing'  Hi, My... named 'datapunt-processing' How to remove the ModuleNotFoundError: No module named 'datapunt-processing' error? Thanks   Hi
ModuleNotFoundError: No module named 'gawseed-processing'
ModuleNotFoundError: No module named 'gawseed-processing'  Hi, My... named 'gawseed-processing' How to remove the ModuleNotFoundError: No module named 'gawseed-processing' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'hathor-processing'
ModuleNotFoundError: No module named 'hathor-processing'  Hi, My... named 'hathor-processing' How to remove the ModuleNotFoundError: No module named 'hathor-processing' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'List_Processing'
ModuleNotFoundError: No module named 'List_Processing'  Hi, My... named 'List_Processing' How to remove the ModuleNotFoundError: No module named 'List_Processing' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'processing-spinner'
ModuleNotFoundError: No module named 'processing-spinner'  Hi, My... named 'processing-spinner' How to remove the ModuleNotFoundError: No module named 'processing-spinner' error? Thanks   Hi, In your

Ads