| Author |
How to store a particular data into project file
|
P Arunkumar
Ranch Hand
Joined: Jan 05, 2012
Posts: 116
|
|
Hi
I wants to store some files into the project, for that i have created a folder inside the project application.
Now i need to store some files dynamically at present iam giving the path of the folder to store like c:\\program files\\---\\--- like this iam storing but i not a right way i think but while iam giving project to client they can store the project in different location that time i will show error for time being i kept like this please help me to solve my problem .
Thanks in advance.
|
 |
Vicky Vijay
Ranch Hand
Joined: Apr 23, 2008
Posts: 125
|
|
Hi Arun,
Try using the below,
<%out.println(request.getRealPath(request.getServletPath()));%>
I hope this fits your requirement ..
|
 |
P Arunkumar
Ranch Hand
Joined: Jan 05, 2012
Posts: 116
|
|
Hi
Thanks for your reply but it is not working for me, below i have given my code please go through it and if i wants to change any thing please guide me.
Web.xml:
Hear i am give the path to store the files what iam uploading.
Now you can see the path to where iam telling the uploaded files to save but i have used method is not good because it is storing in local host, even though iam giving the project path its not a perfect.
Servlet code:
jsp page :
My project is working fine but without error but now i have created one folder under WebContent i need to save the files in that folder not in D:\Eclipse\eclipse\WorkSpace like this how i can solve this problem. please help me. its so urgent.
|
 |
Saurabh Pillai
Ranch Hand
Joined: Sep 12, 2008
Posts: 449
|
|
You should never use absolute path, in your case, use relative path while doing file manipulation, look at HttpServletRequest.html#getContextPath.
I can see you are using Java code inside JSP. That is not a good practice. JSP is used for displaying contents and should not contain any Java code. Any Java code should be move to Java files i.e. Service classes according to MVC architecture. There are tons of benefits using right tool, one of them is maintenance.
Hope this helps. :)
|
 |
Prasad Krishnegowda
Ranch Hand
Joined: Apr 25, 2010
Posts: 503
|
|
|
You tell servlet code, and show us JSP code.. That JSP is full of scriplets, which is a very bad practice. Are you using this JSP only as servlet in your application?
|
Regards, Prasad
SCJP 5 (93%)
|
 |
Senthil Manoharan
Greenhorn
Joined: Mar 01, 2010
Posts: 28
|
|
|
you can use "/<Folder name>" or something like "../<Folder name>" for storing it in subfolder of the parent folder..
|
Thanks and Regards
Senthil Kumar M
|
 |
P Arunkumar
Ranch Hand
Joined: Jan 05, 2012
Posts: 116
|
|
Thanks for your reply
To solve this problem what i want to do, iam new to development field please guide me to solve this. i learned myself no one is not there to guide me so i did some mistake, to rectify the problem please help me.
Thanks in advance.
|
 |
P Arunkumar
Ranch Hand
Joined: Jan 05, 2012
Posts: 116
|
|
Hi
I have change my code into jsp+ servlet files but now iam facing some error please help me to solve, if iam doing mistake please intimate me.It is a file uploading concept.
Jsp Code:
My servlet file is Upload.java
If you say that ServletContext context = pageContext.getServletContext(); in this line its showing error while compiling time cannot find symbol. then i kept
private GenericServlet pageContext;
ServletContext context = pageContext.getServletContext();
now its not showing error compilation fine but while running time its shows the error as
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
Upload.doPost(Upload.java:39)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.33 logs.
in eclipse.
web.xml:
If we wrote java code inside jsp file by scripting is not a good so i change my code please help me to solve my problem
Thanks in advance.
|
 |
 |
|
|
subject: How to store a particular data into project file
|
|
|