farahshafilla 0 Newbie Poster

Drop the table you have and create a new one.

i had been follow your advised.
drop and make a new table.
the problem is not settle.
the image still not save in the database and when i click submit,
it tooks about 4 minutes to loading but the image still not save in the database.
am I too bad?:'(

farahshafilla 0 Newbie Poster

I didn't get you. Are you not creating a table into a database or something else?

At mysql prompt use following commands

>Use database_name
>Create table testimage
(
     imageid varchar(100) primary key,
     imagedata blob
);
>

i already have my own database.
when i change the database name,username and passwoprd,that u give, the image still not save in the database.so im confused,what's wrong with the code.
it is because of my database or others thing.

farahshafilla 0 Newbie Poster

I am uploading a zip containing the code which I had posted in previous thread. I have use NetBeans6.1. Unzip it, open it uwing netbean6.1, change the mysql - database/user/password and (run)deploy it.

still it cannot save in the database.
it is my data base incorrect
my data base is :

CREATE TABLE `testimage` (
  `id` varchar(11) default NULL,
  `image` blob
)
farahshafilla 0 Newbie Poster

Which method is used by you to create a web application? - Manual or NetBeans or something else.

i use netbean 6.1

farahshafilla 0 Newbie Poster

my web server is apache tomcat and the version is 6.0.16

farahshafilla 0 Newbie Poster

adatapos...

i try run your program....
this error appear:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 22 in the generated java file
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:316)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.

i am using apache as my web server

farahshafilla 0 Newbie Poster

i already change the sql statement and also make out.println() method.
but it still display blank page when i run it

farahshafilla 0 Newbie Poster

hi...i have this code.
but i will display blank page when i run it :

import java.io.*;
import java.sql.*;
import java.util.*;
import java.text.*;
import java.util.regex.*;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class UploadImage extends HttpServlet{
  public void doPost(HttpServletRequest request, HttpServletResponse response) 
                throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    System.out.println("request: "+request);
    if (!isMultipart) {
      System.out.println("File Not Uploaded");
    } else {
      FileItemFactory factory = new DiskFileItemFactory();
      ServletFileUpload upload = new ServletFileUpload(factory);
      List items = null;

      try {
        items = upload.parseRequest(request);
        System.out.println("items: "+items);
      } catch (FileUploadException e) {
        e.printStackTrace();
      }
      Iterator itr = items.iterator();
      while (itr.hasNext()) {
        FileItem item = (FileItem) itr.next();
        if (item.isFormField()){
          String name = item.getFieldName();
          System.out.println("name: "+name);
          String value = item.getString();
          System.out.println("value: "+value);
        } else {
          try {
            String itemName = item.getName();
            Random generator = new Random();
            int r = Math.abs(generator.nextInt());

            String reg = "[.*]";
            String replacingtext = "";
            System.out.println("Text before replacing is:-" + itemName);
            Pattern pattern = Pattern.compile(reg);
            Matcher matcher = pattern.matcher(itemName);
            StringBuffer buffer = new StringBuffer();

            while (matcher.find()) {
              matcher.appendReplacement(buffer, replacingtext);
            }
            int IndexOf = itemName.indexOf("."); 
            String domainName = itemName.substring(IndexOf);
            System.out.println("domainName: "+domainName);

            String finalimage = buffer.toString()+"_"+r+domainName;
            System.out.println("Final Image==="+finalimage);

            File savedFile = new File("C:/apache-tomcat-6.0.16/webapps/example/"+"images\\"+finalimage);
            item.write(savedFile);
            out.println("<html>");
            out.println("<body>");
            out.println("<table><tr><td>");
            out.println("<img src=images/"+finalimage+">");
            out.println("</td></tr></table>");

            Connection conn = null;
            String url = "jdbc:mysql://localhost/thundercatz";
            String dbName = "test";
            String driver = "com.mysql.jdbc.Driver";
            String username = "root"; 
            String userPassword = "";
            String strQuery = null;
          //  String strQuery1 = null;
            //String imgLen="";

            try {
              System.out.println("itemName::::: "+itemName);
              Class.forName(driver).newInstance();
              conn = DriverManager.getConnection(url+dbName,username,userPassword);
              Statement st = conn.createStatement(); …
farahshafilla 0 Newbie Poster

i dont understand....

farahshafilla 0 Newbie Poster

how to find to search server logfiles?
i have no idea...

farahshafilla 0 Newbie Poster

hai...
i need idea how to make security code in jsp..
for example:
when we register to any website, mostly we need to fill
the security code that appear at the registration form page.
so how can,I as a developer to do that security code?
this is the example of security code:
how can i call that image to my form?
and it pick randomly from the database

farahshafilla 0 Newbie Poster

hi,
actually i want to set a order id by automatically...
example:

oderId : GB0001

and it will increase automatically each time some one make order.

farahshafilla 0 Newbie Poster

then,may i know how to solve it?

farahshafilla 0 Newbie Poster

i have the below code: its appear error when i run the code:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ page import="java.io.*,java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<html>
<%
int val =0;
StringcontentType = request.getContentType();
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;

while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(saveFile.lastIndexOf("\\")+ 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;

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;

FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos, (endPos - startPos));
%>

<%
Connection con=null;
PreparedStatement pstatement = null;
String line = null;
String value=null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "thundercatz";
String driver = "com.mysql.jdbc.Driver";
String userName = "root"; 
String password = "";
try{
StringBuilder contents = new StringBuilder();
BufferedReader input = new BufferedReader(new FileReader(saveFile));
while (( line = input.readLine()) != null){
contents.append(line);
}
value = contents.toString();
System.out.println("Value:"+value);
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url+dbName,userName,password);
java.util.Date now = new java.util.Date();
String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
String strDateNew = sdf.format(now) ;

String queryString = "INSERT INTO file_tbl set file_data='"+value+"',file_date='"+strDateNew+"'";

//out.println(queryString);

pstatement=con.prepareStatement(queryString);


val = pstatement.executeUpdate();

if(val>0)
{
%>
<br><br>
<b>File <% …
farahshafilla 0 Newbie Poster

ooo..ok...
i try to find it...
tq sir
1

farahshafilla 0 Newbie Poster

actually the blank page appears because the image did not save in the database. ..:(

the page is:

import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.regex.*;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class UploadImage extends HttpServlet {
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        System.out.println("request: " + request);
        if (!isMultipart) {
            System.out.println("File Not Uploaded");
        } else {
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List items = null;

            try {
                items = upload.parseRequest(request);
                System.out.println("items: " + items);
            } catch (FileUploadException e) {
                e.printStackTrace();
            }
            Iterator itr = items.iterator();
            while (itr.hasNext()) {
                FileItem item = (FileItem) itr.next();
                if (item.isFormField()) {
                    String name = item.getFieldName();
                    System.out.println("name: " + name);
                    String value = item.getString();
                    System.out.println("value: " + value);
                } else {
                    try {
                        String itemName = item.getName();
                        Random generator = new Random();
                        int r = Math.abs(generator.nextInt());

                        String reg = "[.*]";
                        String replacingtext = "";
                        System.out.println("Text before replacing is:-" + itemName);
                        Pattern pattern = Pattern.compile(reg);
                        Matcher matcher = pattern.matcher(itemName);
                        StringBuffer buffer = new StringBuffer();

                        while (matcher.find()) {
                            matcher.appendReplacement(buffer, replacingtext);
                        }
                        int IndexOf = itemName.indexOf(".");
                        String domainName = itemName.substring(IndexOf);
                        System.out.println("domainName: " + domainName);

                        String finalimage = buffer.toString() + "_" + r + domainName;
                        System.out.println("Final Image===" + finalimage);

                        File savedFile = new File("C:/apache-tomcat-6.0.16/webapps/example/" + "images\\" + finalimage);
                        item.write(savedFile);
                        out.println("<html>");
                        out.println("<body>");
                        out.println("<table><tr><td>");
                        out.println("<img src=images/" + finalimage + ">");
                        out.println("</td></tr></table>");

                        Connection conn = null;
                        String url = "jdbc:mysql://localhost:3306/";
                        String dbName = "thundercatz";
                        String driver = "com.mysql.jdbc.Driver";
                        String …
farahshafilla 0 Newbie Poster
<html>

<head><title>Image Upload</title></head>

<body>
  <form action="UploadImage" method="post" enctype="multipart/form-data" 
           name="productForm" id="productForm"><br><br>
    <table width="400px" align="center" border=0 style="background-color:ffeeff;">
      <tr>
        <td align="center" colspan=2 style="font-weight:bold;font-size:20pt;">
           Image Details</td>
      </tr>

      <tr>
        <td align="center" colspan=2>&nbsp;</td>
      </tr>

      <tr>
        <td>Image Link: </td>
        <td>
          <input type="file" name="file" id="file">
        <td>
      </tr>

      <tr>
        <td></td>
        <td><input type="submit" name="Submit" value="Submit"></td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>

    </table>
  </form>
</body>

</html>

did u mean this???

farahshafilla 0 Newbie Poster

tq...but a blank page appears...

farahshafilla 0 Newbie Poster

my code :
********uploadImage.jsp*************

<form action="UploadImage" method="post" enctype="multipart/form-data" 
           name="productForm" id="productForm"><br><br>
    <table width="400px" align="center" border=0 style="background-color:ffeeff;">
      <tr>
        <td align="center" colspan=2 style="font-weight:bold;font-size:20pt;">
           Image Details</td>

******UploadImage.java******

import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.regex.*;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class UploadImage extends HttpServlet {
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        System.out.println("request: " + request);
        if (!isMultipart) {
            System.out.println("File Not Uploaded");
        } else {
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List items = null;

            try {
                items = upload.parseRequest(request);
                System.out.println("items: " + items);
            } catch (FileUploadException e) {
                e.printStackTrace();
            }
            Iterator itr = items.iterator();
            while (itr.hasNext()) {
                FileItem item = (FileItem) itr.next();
                if (item.isFormField()) {
                    String name = item.getFieldName();
                    System.out.println("name: " + name);
                    String value = item.getString();
                    System.out.println("value: " + value);
                } else {
                    try {
                        String itemName = item.getName();
                        Random generator = new Random();
                        int r = Math.abs(generator.nextInt());

                        String reg = "[.*]";
                        String replacingtext = "";
                        System.out.println("Text before replacing is:-" + itemName);
                        Pattern pattern = Pattern.compile(reg);
                        Matcher matcher = pattern.matcher(itemName);
                        StringBuffer buffer = new StringBuffer();

                        while (matcher.find()) {
                            matcher.appendReplacement(buffer, replacingtext);
                        }
                        int IndexOf = itemName.indexOf(".");
                        String domainName = itemName.substring(IndexOf);
                        System.out.println("domainName: " + domainName);

                        String finalimage = buffer.toString() + "_" + r + domainName;
                        System.out.println("Final Image===" + finalimage);

                        File savedFile = new File("C:/apache-tomcat-6.0.16/webapps/example/" + "images\\" + finalimage);
                        item.write(savedFile);
                        out.println("<html>");
                        out.println("<body>");
                        out.println("<table><tr><td>");
                        out.println("<img src=images/" + finalimage + ">");
                        out.println("</td></tr></table>");

                        Connection conn = null;
                        String url = "jdbc:mysql://localhost:3306/";
                        String dbName = "thundercatz"; …