Results 1 to 4 of 4
- 04-06-2011, 12:11 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
How to get the values from one jsp page to another jsp page
Hi
I have one jsp page with two text fields and one file upload button. Successfully i can upload the file to a specific folder.
But the problem is when i am trying to get the values from those textfields in another jsp/servlet, i got null values for the textfields. I have written the code in second jsp page for both uploading and get the values of textfields.Please help me.
Thanks in Advance.
My second jsp page code is below:
import java.io.DataInputStream;
import com.ajel.Getcon;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Upload
*/
public class Upload extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
PrintWriter out=res.getWriter();
res.setContentType("text/html");
String rname=req.getParameter("recruiter");
out.println(rname);
String contentType = req.getContentType();
try {
Connection con=Getcon.getConnection();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(req.getInputStream());
//we are taking the length of Content type data
int formDataLength = req.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("\""));
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
saveFile="E:\\workspace\\Ajelsite\\Resumes\\"+save File;
FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
out.println("File saved as " +saveFile);
}
}
}
- 04-06-2011, 12:53 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Use opensource fileupload apis like cos.jar or apache-commons-fileupload which allow you to read both the file and the parameters submitted with the file.
To get the parameters to display on the second JSP you'd need to set them in some scope (request or session) in the servlet before forwarding to that second JSP.
- 04-07-2011, 06:24 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Please send me the sample code.
Thanks in advance.
- 04-07-2011, 06:27 AM #4
This is a forum, not a code factory. Recmmended reading: How to ask questions the smart way
db
Similar Threads
-
Displaying array values in jstl page
By keshaba in forum Advanced JavaReplies: 0Last Post: 04-23-2010, 10:00 AM -
Submit values to a parent page
By carag in forum New To JavaReplies: 1Last Post: 12-11-2009, 12:33 AM -
to retrieve multiple values from html page through jsp
By raghu9198 in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 02-17-2009, 02:43 PM -
unable to update MYSQL with values from jsp page
By koushika in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-27-2008, 01:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks