Good day experts, i want to upload image and forms input to database using apachae method but it returns an error display below
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 36 in the jsp file: /jsp/cat1.jsp
name cannot be resolved
33: String fvalue = item.getString();
34:
35: if (fname.equals("name"))
36: name = fvalue.toString();
37: if (fname.equals("city"))
38: city = fvalue.toString();
39:
An error occurred at line: 38 in the jsp file: /jsp/cat1.jsp
city cannot be resolved
35: if (fname.equals("name"))
36: name = fvalue.toString();
37: if (fname.equals("city"))
38: city = fvalue.toString();
39:
40: b = item.get();
41: name = item.get();
An error occurred at line: 41 in the jsp file: /jsp/cat1.jsp
name cannot be resolved
38: city = fvalue.toString();
39:
40: b = item.get();
41: name = item.get();
42: city = item.get();
43: }
44: }
An error occurred at line: 42 in the jsp file: /jsp/cat1.jsp
city cannot be resolved
39:
40: b = item.get();
41: name = item.get();
42: city = item.get();
43: }
44: }
45:
An error occurred at line: 49 in the jsp file: /jsp/cat1.jsp
name cannot be resolved
46:
47:
48: psImageInsertDatabase.setBytes(1,b);
49: psImageInsertDatabase.setString(2,name);
50: psImageInsertDatabase.setString(3,city);
51: int i = psImageInsertDatabase.executeUpdate();
52: if(i!=0){
An error occurred at line: 50 in the jsp file: /jsp/cat1.jsp
city cannot be resolved
47:
48: psImageInsertDatabase.setBytes(1,b);
49: psImageInsertDatabase.setString(2,name);
50: psImageInsertDatabase.setString(3,city);
51: int i = psImageInsertDatabase.executeUpdate();
52: if(i!=0){
53: pw.println("<br>Record has been inserted successfully");
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)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
here is my code
<%@ page import="java.sql.*" %>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="org.apache.commons.io.output.*"%>
<%@ page import="org.apache.commons.fileupload.servlet.*"%>
<%@ page import="org.apache.commons.fileupload.disk.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%
Connection connection;
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/goodness","mutago", "mutag566");
byte[] b=null;
try{
//String name = request.getParameter("name");
//String city = request.getParameter("city");
PreparedStatement psImageInsertDatabase= connection.prepareStatement("insert into picture (image,name,city)values(?,?,?)");
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(factory);
List items = sfu.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (!item.isFormField())
{
String fname = item.getFieldName();
String fvalue = item.getString();
if (fname.equals("name"))
name = fvalue.toString();
if (fname.equals("city"))
city = fvalue.toString();
b = item.get();
name = item.get();
city = item.get();
}
}
psImageInsertDatabase.setBytes(1,b);
psImageInsertDatabase.setString(2,name);
psImageInsertDatabase.setString(3,city);
int i = psImageInsertDatabase.executeUpdate();
if(i!=0){
pw.println("<br>Record has been inserted successfully");
}
else{
pw.println("failed to insert the data");
}
}
catch(Exception e)
{
pw.println(e);
e.printStackTrace();
response.sendRedirect("cat.jsp");
}
%>
Pls what do I do. Thanks