Mohammad Ali

Greenhorn
+ Follow
since Jan 03, 2006
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mohammad Ali

please guide me how to call PHP code from a servlet... thanks
18 years ago
Please guide me how to call PHP file from a servlet. I found php code which can create file on my server directory. But i want to call that php code from my servlet. Php code is in the php file named UpLoad_File.php
I also want to pass the file name as a parameter to php file. Also is it possible after executing PHP code the control return back to servlet.. is that possible...Thanks
18 years ago
Please guide me, i am stuck with this picture uploading problem, I rent a space on a shared tomcat server from a serevice provider, i am not allowed to customise tomcat in any way. My application works perfect when i run the same java code on my local laptop machinem , i do not understand why tomcat write to a windows directory on my local machine but unable to write on the server directory. I do not want to store images in database bcz of loading/unloading images from table takes to much time and is not a good smart solution. I appreciate all help from this forum. I wait for your advise.... Thanks
18 years ago
Hello, Bill i removed the code from CATCH but still it is not able to write image file on my server directory, it is throwing the following error , please guide me what i am doing wrong, the same code is working fine and loading images when i run the app on my laptop locally

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

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

exception

java.security.AccessControlException: access denied (java.io.FilePermission /web/tomcat/temp/upload__10c3edf7_1094f5d6d15__7ffe_00000002.tmp write)
java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
java.security.AccessController.checkPermission(AccessController.java:427)
java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
java.lang.SecurityManager.checkWrite(SecurityManager.java:962)
java.io.FileOutputStream.<init>(FileOutputStream.java:169)
java.io.FileOutputStream.<init>(FileOutputStream.java:131)
org.apache.commons.io.output.DeferredFileOutputStream.thresholdReached(DeferredFileOutputStream.java:122)
org.apache.commons.io.output.ThresholdingOutputStream.checkThreshold(ThresholdingOutputStream.java:221)
org.apache.commons.io.output.ThresholdingOutputStream.write(ThresholdingOutputStream.java:128)
org.apache.commons.fileupload.MultipartStream.readBodyData(MultipartStream.java:520)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:371)
org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:116)
com.example.model.ServletController.processRequest(ServletController.java:135)
com.example.model.ServletController.doPost(ServletController.java:1597)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:239)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:266)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:157)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.
18 years ago
Please I need help, i am trying to write an image file to the web server directory but i am not able to write image file on the web server directory. I am using Apachee Fileupload to write image file on server directory. My java code works fine when i run the application locally on my laptop but once i upload the application on the server it does not let me write the image to the directory on web host server. I checked the permissions on my server directory they are all good rwx on all user group and public. please give me advise what i am doing wrong.

boolean isMultipart = FileUpload.isMultipartContent(request);

if ( isMultipart == true) {

String fieldname = null;
String fieldvalue = null;
String fileName = null;


DiskFileItemFactory factory = new DiskFileItemFactory();
// Configure the factory here, if desired.
ServletFileUpload diskFileUpload = new ServletFileUpload(factory);
// Configure the uploader here, if desired.


List fileItemsList = null;
try {
// diskFileUpload.setSizeThreshold(40960);
// diskFileUpload.setSizeMax(81920);

fileItemsList = diskFileUpload.parseRequest(request);
} catch (FileUploadException ex) { ex.printStackTrace(); }

String optionalFileName = "";
FileItem fileItem = null;
col_name_coma = "";
col_value_coma = "";
name_value = "";

Iterator it = fileItemsList.iterator();
while (it.hasNext()){
FileItem fileItemTemp = (FileItem)it.next();

// fieldname = fileItemTemp.getFieldName();
// fieldvalue = fileItemTemp.getString();


if (fileItemTemp.isFormField()){
fieldname = fileItemTemp.getFieldName();
fieldvalue = fileItemTemp.getString();
if (fieldname.equals("profile_id")) {
profile_id = fieldvalue;
col_name_coma = col_name_coma + fieldname +",";
col_value_coma = col_value_coma + "'"+fieldvalue+"','";
}
if (fieldname.equals("Router"))
{ router = fieldvalue; }
if (fieldname.equals("DisplayInputForm"))
{ display_input_form = fieldvalue; }
if (fieldname.equals("UserType"))
{ user_type = fieldvalue; }
if (fieldname.equals("display_option")) {
display_option = fieldvalue;
col_name_coma = col_name_coma + fieldname +",";
col_value_coma = col_value_coma + fieldvalue+"','";

}

if (fileItemTemp.getFieldName().equals("filename")) optionalFileName = fileItemTemp.getString();
}
else fileItem = fileItemTemp;

if (fileItem!=null){ // label-A

fileName = fileItem.getName();

// Uploaded File Info
// Content type: <%= fileItem.getContentType() %><br/>
// Field name: <%= fileItem.getFieldName() %><br/>
// File name: <%= fileName %><br/>
// File size: <%= fileItem.getSize() %><br/><br/>


/* Save the uploaded file if its size is greater than 0. */
if (fileItem.getSize() > 0){ // label-B
if (optionalFileName.trim().equals("")) {
fileName = (new File(fileName)).getName();
File saveTo = new File(fileName);
// fileName = profile_id + "-"+ fileName;
String picture_no = fileItem.getFieldName();
col_name_coma = col_name_coma + picture_no +",";
col_value_coma = col_value_coma + saveTo +"','";
name_value = name_value +" , "+picture_no+" = "+"'"+saveTo+"'";
// col_value_coma = col_value_coma + fileName +"','";
// name_value = name_value +" , "+picture_no+" = "+"'"+fileName+"'";
} else {
fileName = profile_id + "-"+ optionalFileName;
String picture_no = fileItem.getFieldName();
col_name_coma = col_name_coma + picture_no +",";
col_value_coma = col_value_coma + fileName +"','";
name_value = name_value +" , "+picture_no+" = "+"'"+fileName+"'";
}

String dirName = "/images/member/";

File saveTo = new File(dirName + fileName);
try {
fileItem.write(saveTo);
save_database(col_name_coma,col_value_coma);
request.setAttribute("tran_result","File uploaded Sucessfully");
request.setAttribute("page_type","any");
request.setAttribute("page_name","TransactionResult.jsp");
RequestDispatcher view = request.getRequestDispatcher("main_page.jsp");
response.setContentType("text/html;charset=UTF-8");
view.forward(request, response);
return;
//<b>The uploaded file has been saved successfully.</b>
}
catch (Exception e){

request.setAttribute("tran_result","File Not Loaded");
request.setAttribute("page_type","any");
request.setAttribute("page_name","TransactionResult.jsp");

RequestDispatcher view = request.getRequestDispatcher("main_page.jsp");
response.setContentType("text/html;charset=UTF-8");
view.forward(request, response);
return;
// <b>An error occurred when we tried to save the uploaded file.</b>
} // end-catch
} // end-label-B
} // end-label-A
} // end-while
} // end multi-part = tru
18 years ago
Please I need help, i am trying to write an image file to the web server directory but i am not able to write image file on the web server directory. I am using Apachee Fileupload to write image file on server directory. My java code works fine when i run the application locally on my laptop but once i upload the application on the server it does not let me write the image to the directory on web host server. I checked the permissions on my server directory they are all good rwx on all user group and public. please give me advise what i am doing wrong.

boolean isMultipart = FileUpload.isMultipartContent(request);

if ( isMultipart == true) {

String fieldname = null;
String fieldvalue = null;
String fileName = null;


DiskFileItemFactory factory = new DiskFileItemFactory();
// Configure the factory here, if desired.
ServletFileUpload diskFileUpload = new ServletFileUpload(factory);
// Configure the uploader here, if desired.


List fileItemsList = null;
try {
// diskFileUpload.setSizeThreshold(40960);
// diskFileUpload.setSizeMax(81920);

fileItemsList = diskFileUpload.parseRequest(request);
} catch (FileUploadException ex) { ex.printStackTrace(); }

String optionalFileName = "";
FileItem fileItem = null;
col_name_coma = "";
col_value_coma = "";
name_value = "";

Iterator it = fileItemsList.iterator();
while (it.hasNext()){
FileItem fileItemTemp = (FileItem)it.next();

// fieldname = fileItemTemp.getFieldName();
// fieldvalue = fileItemTemp.getString();


if (fileItemTemp.isFormField()){
fieldname = fileItemTemp.getFieldName();
fieldvalue = fileItemTemp.getString();
if (fieldname.equals("profile_id")) {
profile_id = fieldvalue;
col_name_coma = col_name_coma + fieldname +",";
col_value_coma = col_value_coma + "'"+fieldvalue+"','";
}
if (fieldname.equals("Router"))
{ router = fieldvalue; }
if (fieldname.equals("DisplayInputForm"))
{ display_input_form = fieldvalue; }
if (fieldname.equals("UserType"))
{ user_type = fieldvalue; }
if (fieldname.equals("display_option")) {
display_option = fieldvalue;
col_name_coma = col_name_coma + fieldname +",";
col_value_coma = col_value_coma + fieldvalue+"','";

}

if (fileItemTemp.getFieldName().equals("filename")) optionalFileName = fileItemTemp.getString();
}
else fileItem = fileItemTemp;

if (fileItem!=null){ // label-A

fileName = fileItem.getName();

// Uploaded File Info
// Content type: <%= fileItem.getContentType() %><br/>
// Field name: <%= fileItem.getFieldName() %><br/>
// File name: <%= fileName %><br/>
// File size: <%= fileItem.getSize() %><br/><br/>


/* Save the uploaded file if its size is greater than 0. */
if (fileItem.getSize() > 0){ // label-B
if (optionalFileName.trim().equals("")) {
fileName = (new File(fileName)).getName();
File saveTo = new File(fileName);
// fileName = profile_id + "-"+ fileName;
String picture_no = fileItem.getFieldName();
col_name_coma = col_name_coma + picture_no +",";
col_value_coma = col_value_coma + saveTo +"','";
name_value = name_value +" , "+picture_no+" = "+"'"+saveTo+"'";
// col_value_coma = col_value_coma + fileName +"','";
// name_value = name_value +" , "+picture_no+" = "+"'"+fileName+"'";
} else {
fileName = profile_id + "-"+ optionalFileName;
String picture_no = fileItem.getFieldName();
col_name_coma = col_name_coma + picture_no +",";
col_value_coma = col_value_coma + fileName +"','";
name_value = name_value +" , "+picture_no+" = "+"'"+fileName+"'";
}

String dirName = "/images/member/";

File saveTo = new File(dirName + fileName);
try {
fileItem.write(saveTo);
save_database(col_name_coma,col_value_coma);
request.setAttribute("tran_result","File uploaded Sucessfully");
request.setAttribute("page_type","any");
request.setAttribute("page_name","TransactionResult.jsp");
RequestDispatcher view = request.getRequestDispatcher("main_page.jsp");
response.setContentType("text/html;charset=UTF-8");
view.forward(request, response);
return;
//<b>The uploaded file has been saved successfully.</b>
}
catch (Exception e){

request.setAttribute("tran_result","File Not Loaded");
request.setAttribute("page_type","any");
request.setAttribute("page_name","TransactionResult.jsp");

RequestDispatcher view = request.getRequestDispatcher("main_page.jsp");
response.setContentType("text/html;charset=UTF-8");
view.forward(request, response);
return;
// <b>An error occurred when we tried to save the uploaded file.</b>
} // end-catch
} // end-label-B
} // end-label-A
} // end-while
} // end multi-part = tru
18 years ago
Please guide me how to upload image in a table in a database.
please give me code how to upload an image file in a table in a Mysql database.
18 years ago
I am attaching the error which comes after i tried to login my application.
The index.jsp page comes fine but when i tried to login in my application using user-id/passowrd the Following Error comes on the server when i try to enter my application using
userid = guest
password = guest.

The Error
=========

HTTP Status 404 - Servlet ShadiManager is not available

--------------------------------------------------------------------------------

type Status report

message Servlet ShadiManager is not available

description The requested resource (Servlet ShadiManager is not available) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.9
18 years ago
Please help me write correct url in my web.xml file. The following is my web.xml entry for my controller servlet.The following entry works fine when i run my application on my local laptop machine. I just cannot figure out what to write in my url mapping for my contrioller servlet so that my controller servlet can be found on the server once the application is uploaded on the host server on the internet.
My application name = ROOT.war
My hosting directory = http://javafaces.s43.eatj.com.
Please help me write the correct url mapping for my controller servlet.......Thanks

<servlet>
<servlet-name>ShadiManager</servlet-name>
<servlet-class>com.example.model.ServletController</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>ShadiManager</servlet-name>
<url-pattern>/ShadiManager</url-pattern>
</servlet-mapping>
18 years ago
Please guide me where to put my Gzip filter in my web directory structure.
I am listing my web.xml entry for the filter. Currently my filter is sitting in a filter package. when i run the app it gives an error saying
Error:
-------
FAIL - Application at context path /CofeeAdvice could not be started

please guide me what to do, if i remove my xml entry for the filter then my app runs otherwise it gives above error....Thanks

<filter>
<filter-name>GzipFilter</filter-name>
<filter-class>com.example.filter.GzipFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>GzipFilter</filter-name>
<url-pattern>/*.jsp</url-pattern>
</filter-mapping>
18 years ago
I desigend a J2EE Aplication using JSP and Servlets in MVC design.
My system was working great untill i tried using filter for gzip compression for response output , after i used filter gzip, my whole application is destroyed, I cannot able to connect to my Mysql data base, my connection object always returns NULL, i tried every thing re-installing the mysql driver, re-installing the NetBeans ide , nothing is working, i am not able to connect with the database.

This application was working perfect before i experimented with the Gzip filter.please any body can help me what i did wrong, did i corrupted tomcat server. My application is still on my laptop and is not have been loaded on internet yet. i am posting some errors it is showing on the tomcat log.

I Want to mention i am using connection pooling which was working great,
all the servlets are present in the application, the whole application and connection pooling was working great before i used this gzip filter.....Also i like to mention the main problem is when i try to load the driver for Mysql database in my java class it always returns a null connection object. I use Class.forName function in java to load a driver for mysql database.Following is the code where my appliacation returns null connection object

public static Connection ConnectDB(String NameParm, String PasswordParm) {
try {

String url = "jdbc:mysql://localhost:3306/mysql";

Class.forName("com.mysql.jdbc.Driver");
conn = null;
conn = DriverManager.getConnection(url, NameParm, PasswordParm);
System.out.println("Database connection established");
return conn;
} catch (Exception e)
{
System.err.println("Cannot connect to database server ");
return conn;
}
}

please guilde me.. my application is totally stoped at this moment.


=========== E R R O R S- ON TOMCAT LOG ============
Jan 3, 2006 3:28:16 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@3a9bba')
Jan 3, 2006 3:28:16 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1c5ddc9')
Jan 3, 2006 3:28:16 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@163f7a1')
Jan 3, 2006 3:28:16 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextDestroyed()
Jan 3, 2006 3:28:16 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextDestroyed()
Jan 3, 2006 3:28:32 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet ShadiManager as unavailable
Jan 3, 2006 3:28:32 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /CofeeAdvice threw load() exception
javax.servlet.UnavailableException: Couldn't create connection pool
at com.example.model.ServletController.init(ServletController.java:69)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:925)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3857)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4118)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:589)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:536)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:471)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1102)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:683)
at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)
Jan 3, 2006 3:28:33 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Jan 3, 2006 3:28:33 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Jan 3, 2006 3:28:34 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class com.sun.faces.config.ConfigureListener
java.lang.NoClassDefFoundError: javax/faces/FacesException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2328)
at java.lang.Class.getConstructor0(Class.java:2640)
at java.lang.Class.newInstance0(Class.java:321)
at java.lang.Class.newInstance(Class.java:303)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3618)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4104)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:589)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:536)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:471)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1102)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:683)
at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)
Jan 3, 2006 3:28:34 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
[ January 03, 2006: Message edited by: Bear Bibeault ]
18 years ago