Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Form Processing Problem
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Lusan Das
Form Processing Problem
0 Answer(s)      a year and 5 months ago
Posted in : JSP-Servlet


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


Advertisement
View Answers

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
Form processing using Bean
Form processing using Bean In this section, we will create a JSP form using bean ,which will use a class file for processing. The standard way of handling... to each field in the form.  The class fields must have "setters"
Advertisements
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
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
Problem when resizing the form - Swing AWT
Problem when resizing the form  Hi, I am facing a problem when resizing the form. I have a JTextPane on the JInternalFrame which occupy all the form space at initial stage. we have a button to add a new JTextPane on the form
New Problem in Form Resizing - Swing AWT
New Problem in Form Resizing  Hi, I am using a MDI application...)); The problem is arising when the user resizes the form. The EditorPane(old... the form? This problem is occuring only the components which are added
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
Problem submitting a struts form containing a dojo script - Struts
Problem submitting a struts form containing a dojo script  Hello there, Is there any way to make use of dojo with struts 1 ? Actually, I'm facing a problem submitting a struts form containing a dojo script for a dynamic
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"> <
Steps for the payment gateway processing?
Steps for the payment gateway processing?  Steps for the payment gateway processing
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
Abort JSP processing
Abort JSP processing  Can I just abort processing a JSP?   Yes. You can put a return statement to abort JSP processing
Speech Processing - Java Beginners
Speech Processing  I want to implement Speech Processing in Java. How can I do It? Please Answer me
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
form
form   Can I prevent a form from being submitted again
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>
image processing - Java3D
image processing  hii i have to compare 2 images. for this i try to convert image into greyscale. i think the greyscale comparisonn is more effective than that of colour. pls give me the processing details.  Hi friend
Image Processing Java
Image Processing Java  Using This Code I Compressed A JPEG Image And the Original Size of the image is 257kb and The Compressed Image Size Is 27kb How Can I Decompress It Please Give Me The "SOURCE CODE" And Hee is my Source Code
JavaScript array processing
JavaScript array processing       By processing array we simply mean that processing.... In this example of processing JavaScript array we have three array objects emp1, emp2
The CPU(Central processing unit)consist of
The CPU(Central processing unit)consist of  The CPU(Central processing unit)consist of 1. Input, Output, and Processing 2. Control Unit, Primary storage, and Secondary storage 3. Control unit, arithmetic logic unit
JDBC Batch Processing
JDBC Batch Processing In this section we are discussing about JDBC Batch processing. You will learn how to write Java programs for JDBC batch processing. The JDBC Batch processing is the mechanism where a group of related SQL statements
What is Parallel Processing?
What is Parallel Processing Parallel processing is a process that allows the processing of multiple program instructions and operations simultaneously... time. The concept of parallel processing has been taken from the human brain
Parallel Processing & Multitasking
Parallel Processing & Multitasking       Multitasking & Multithreading Multitasking allow to execute more than one tasks at the same time, a task being a program
Processing stored procedure in MySQL - SQL
Processing stored procedure in MySQL  Dear All java with mysql developer..... i need to convert my SQL procedure to MySQL database... here is my Stored procedure in SQL.... create or replace procedure INVNAMES (bno
Spring 3.2 Asynchronous Request Processing
In this section, you will learn about Asynchronous Request Processing in Spring MVC 3.2.
 

 

 

DMCA.com