1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

JSP interview questions

  • How do i include static files within a jsp page ? view answer
  • Image upload from JSP to DataBase ? view answer
  • How to Disable session in JSP page ? view answer
  • Q.How you do Session Management in JSP ? view answer
  • How can get the checked values from multiple check box checked ? or How to Handle multiple check box checked ? view answer
  • Q.How to send email through JSP/Java? view answer
  • Q.How to create and retrive a multiple selections list in jsp/servlet? view answer
  • Q.How to create a drop down list in jsp? view answer
  • Q. How to add and delete Cookie in jsp ? view answer
  • Q. How to Protect JSPs from direct access ? view answer
  • Q.How to upload an image from servlet/jsp into server from clients machine? view answer
  • Q.How do you delete a Cookie within a JSP? view answer
  • Q.How do you prevent the Creation of a Session in a JSP Page and why? view answer
  • Q.How does a servlet communicate with a JSP page? view answer
  • Q.which situation you use static include and dynamic include in jsp? view answer
  • Q.Difference between static include and dynamic include in JSP ? view answer
  • q.What's the Difference between Forward and Include? view answer
  • Q.How do you pass control from one JSP page to another? view answer
  • Q.How can I declare methods within my JSP page? view answer
  • Q.How can I implement a thread-safe JSP page? view answer
  • Q.How does JSP handle run-time exceptions? view answer
  • Q.How do I perform browser redirection from a JSP page? view answer
  • Q.How do I include static files within a JSP page? view answer
  • Q.How many JSP scripting elements and what are they? view answer
  • Q.What are the implicit objects? view answer
  • Q.How does a try statement determine which catch clause should be used to handle an exception? view answer
  • Q.How do I prevent the browser from caching my dynamic content? view answer
  • Q.Explain the life-cycle mehtods in JSP? view answer
  • Q.What are the different scope valiues for the ? view answer
  • What are implicit objects in JSP? view answer
  • What is a Expression,Declaration,Scriptlet in jsp? view answer
  • What is a Visible and Hidden Comment in jsp? view answer
  • Q. What is a Expression? view answer

!!! JSP interview questions !!!

Q.How to upload an image from servlet/jsp into server from clients machine?


SCJP 1.5/1.6 Exam Kit
SCWCD 1.5 Exam Kit

Image upload from JSP to Data Base step by step :

step 1 :
In the JSP
<form name="regform2" method="post" enctype="multipart/form-data">
<input type="file" name="ImageFile" id="ImageFile" onChange="uploadImage()"/>
</form>

java script :
function uploadImage(){
document.regform.action ="<%=request.getContextPath()%>/dfdmin?cmd=uploadimage";
document.regform.submit();
}


Step 2.
In the servlet - add the below code.
This will upload your image to server (D:\\) or In unix you can mention /home/user like that

String rtempfile = File.createTempFile("temp","1").getParent();
MultipartRequest multi = new MultipartRequest(request, rtempfile, 500000 * 1024);
File rnewfile=null;
rnewfile = new File("D:\\"+"jsp"+File.separator+"images"+File.separator+"uploadImage"+File.separator);
if(rnewfile.exists()){
}else{
rnewfile.mkdirs();
}

File f = multi.getFile("ImageFile");
System.out.println(f.getName());
FileInputStream fin =new FileInputStream(f);
RandomAccessFile r = new RandomAccessFile(rnewfile+File.separator+f.getName(),"rw");
filename = f.getName();
// FileOutputStream fos =new FileOutputStream(rnewfile);
byte sizefile[] = new byte[5000000];
fin.read(sizefile);
// fos.write(sizefile);
r.write(sizefile);
//fos.close();
r.close();
fin.close();

DAO.upload(f); // Call to DAO for insert image into database.

Step 3.

Then call to DAO to save this image to data base.
Insert into Database
public void upload(File f){
InputStream is = new FileInputStream(f);
String sql = " INSERT INTO image_upload (IMAGE) VALUES (?) ";
pStmt = conn.prepareStatement(sql);
pStmt.setBinaryStream(1, is, (int)(f.length()));
pStmt.execute();
conn.commit();
}



This will upload multipart file to your data base.

Note : get cos.jar from oreilly website


OR
if your server have already image file then just do below step




Code is here :
File f = new File("d:\\test.jpg");
InputStream is = new FileInputStream(f);
String sql = " INSERT INTO image_upload (IMAGE) VALUES (?) ";
pStmt = conn.prepareStatement(sql);
pStmt.setBinaryStream(1, is, (int)(f.length()));
pStmt.execute();
conn.commit();

This will work.

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy