• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing parameter from jsp to text file

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to pass a variable from JSP to a file ? i have tried using this.

1
String unixCommand = "sudo echo hello >> write abc.txt
Runtime rt = Runtime.getRuntime();
rt.exec(unixCommand);
2
sudo sh -c echo Text I want to write > /path/to/file
3
echo Text I want to write | sudo tee /path/to/file > /dev/null

and another is , for example i send parameter with value testpara and i want this testpara on my textfile just like using php using$1 something like that, i have tried using <%=parameter%> but doesnt seem work TT
 
Author and all-around good cowpoke
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you thinking of JSP for this? JSP is designed for making it easy to create HTML pages, not conduct server side file operations.

Your first step should be writing a plain Java class that can perform the Runtime exec functions you want.

Only after that is running and taking care of the std out and std err streams should you consider how to integrate it into a servlet/jsp environment.

Bill
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hha..., i just want to tried it, i have tried Runtime exec and it run well, but when echo(linux command) doesn't seem work, i want to know how to get it run :D

or can you tell me how to parse parameter from jsp to textfile ? like passing parameter from jsp to another jsp , but this one is to textfile :D
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i need to know is it possible to pass parameter from jsp to text file, someone please answer me this, i just need to know is it possible or not
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Pass" data? No. Text documents have no active elements to process parameters. So, as asked, no.

But it's not clear what you are actually trying to accomplish, so it's not really possible to guess how it could actually be accomplished.
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm sorry if i not clearly explain what i really want to do, what i want really is like this

if on PHP i do this

shell_exec("./sh.sh $opt1 $opt2");

and on shell

echo "My $1 will kick your $2 anytime"

i need the JSP version
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I repeat a previous question: why in a JSP. It sure doesn't seem like it's something that should be done in a JSP. That's some serious code smell there.
 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The real reason is, i have a assignment to do and i tell them i'll do it with JSP, and i dont know this problem will come and i cant solve it , so i need you guys to tell me is this possible to do or not , so i have some reason to change the programming language
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can't be done directly using standard JSP syntax.

It can be done in java code.
There are also java libraries for file handling, so rather than using Runtime.exec if what I wanted to do was log to a file, I would use the java library by preference.

You can embed java code in a JSP using <% %> tags.
So theoretically you CAN do it in a JSP.
You just probably shouldn't, because java code in a JSP is bad. Ok?

Also, JSP pages are intended to produce HTML pages.
A well engineered application doesn't let JSP pages do anything other than that.

A servlet would probably be the most appropriate place to put code relating to file manipulation.

Yes this is more complex than the PHP equivalent.
And yes it is a purist approach to the architecture.

You CAN do this in JSP, it is just not recommended.

 
Irvan Kosini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Stefan Evans, from your reply i see i can do it with it, can you show me how to do it, for passing parameter? with java, if it can do it with java then i dont have the reason to change it because it can done with java, i know it is not recommended but i still want to know how to do it because i have stuck with this for couple weeks, thanks
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're in an environment where JSPs work, then you are in an environment where servlets work, and you can completely avoid doing this using a hacked about JSP page.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you ever thought that the reason you are meeting such technical (and advisory) resistance is because it's the wrong way to go about it?

"I'm having trouble getting this screw in... maybe I'm using the wrong tool?"

 
Irvan Kosini
Ranch Hand
Posts: 43
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lol, thanks for the advice and i'll try persuade for changing the programming language

Thank you very much
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Irvan Kosini wrote:Lol, thanks for the advice and i'll try persuade for changing the programming language


It's not the language that needs changing, just the design. Forget about JSPs and servlets for the moment. Create a plain Java class that does what you want. Then we'll explain how to integrate it into a web application.
reply
    Bookmark Topic Watch Topic
  • New Topic