aspose file tools*
The moose likes Servlets and the fly likes Which  server-side script  takes the input from JavaScript in j2ee application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Which  server-side script  takes the input from JavaScript in j2ee application" Watch "Which  server-side script  takes the input from JavaScript in j2ee application" New topic
Author

Which server-side script takes the input from JavaScript in j2ee application

Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
Which server-side script takes the input from JavaScript, can access the database if it needs to, and processes the data.
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Rajendra Prakash wrote:Which server-side script takes the input from JavaScript, can access the database if it needs to, and processes the data.


Rajendra, your question (?) doesn't make sense, please clarify!

What are you trying to achieve, what are you having problems with? (Don't know how to pass parameters from JS to the server-side app? Don't know which scripting language can access those parameters? Don't know how to process them in a servlet in Java?? )


OCJP 6 (93%)
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9311
    
  17

Javascript variables cannot be accessed in servlets. javascript is executed on the client side. You'll have to make a request to the server (maybe an Ajax call) to send the values of the javascript variables which you want to process on the server side...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
Here is how the usual AJAX script goes:

* Some action triggers the event, like the user clicking a button.
* The AJAX call fires, and sends a request to a server-side script, using XML
* The server-side script (PHP, ASP, or whatever) takes the input from JavaScript, can access the database if it needs to, processes the data.
* Using XML again, the script sends the data back to the original client-side page that made the request
* A second JavaScript function, called a callback function,catches the data, and updates the web page


From this lines i asked you
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9311
    
  17

The AJAX call fires, and sends a request to a server-side script, using XML

This is the key step. You'll have to send any request parameters to the server in the Ajax request. It can be sent as query string if the ajax request is a GET request or as request body if you are using POST Ajax request. Search on the internet for some tutorial on how to send parameters in an Ajax request...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61591
    
  67

Rajendra Prakash wrote:Here is how the usual AJAX script goes: ... sends a request to a server-side script using XML ... Using XML again

XML is not used when sending the request to the sever, and XML is only one of many text formats that can be used for the response.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
Is it possible to use jsp(server side scirpt ) to take the input from JavaScript, can access the database if it needs to, processes the data.
luke yu
Greenhorn

Joined: Oct 20, 2008
Posts: 8
of course you can access database using jsp(scriptlet )
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9311
    
  17

Rajendra Prakash wrote:Is it possible to use jsp(server side scirpt ) to take the input from JavaScript, can access the database if it needs to, processes the data.

Your question is still not clear. I hope this is not what you are expecting (as it is not possible)

"A page is opened in the user's browser. You set the value of a javascript variable to 10. The page is posted back to the server. You try to access the value 10 from the javascript variable"

As I said earlier, to send a request to the server using javascript, you'll either have to make an ajax request, or open a new pop-up window from javascript using window.open...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61591
    
  67

luke yu wrote:of course you can access database using jsp(scriptlet )

Only if you want to dabble in extremely poor practices and write code like it's still 1998.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Tonight I'm gonna code like it's nineteen..... nine...ty nine.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Bear Bibeault wrote:
Only if you want to dabble in extremely poor practices and write code like it's still 1998.

David wrote:
Tonight I'm gonna code like it's nineteen..... nine...ty nine.


I completly Agree . but what to do ? . but somebody[most of the programmer(since maintenance project is more)] still need to code (change) java code in jsp. Even many small company use to code java in jsp in development project still(2009) .

if client pay for you to write this in 2009, you should... right?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61591
    
  67

No one is talking about maintaining old pages, but coding new ones (or refactoring to bring pages that need lots of changes into the modern era).

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And the business value for moving the code out of the JSPs is there anyway, as it makes things more testable (if done correctly), easier to document, and so on.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which server-side script takes the input from JavaScript in j2ee application