• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to store a particular data into project file

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Arun,

Try using the below,

<%out.println(request.getRealPath(request.getServletPath()));%>


I hope this fits your requirement ..
 
P Arunkumar
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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. :)
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use "/<Folder name>" or something like "../<Folder name>" for storing it in subfolder of the parent folder..
 
P Arunkumar
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic