IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Servlets
 
RSS feed
 
New topic
Author

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

Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Messages: 87

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
Messages: 253

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?? )
Ankit Garg
Bartender

Joined: Aug 03, 2008
Messages: 6371

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.0 98%, SCWCD 5 98%, Javaranch SCJP FAQ, SCWCD Links
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Messages: 87

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
Bartender

Joined: Aug 03, 2008
Messages: 6371

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...

SCJP 6.0 98%, SCWCD 5 98%, Javaranch SCJP FAQ, SCWCD Links
Bear Bibeault
Author and opinionated walrus
Sheriff

Joined: Jan 10, 2002
Messages: 36592

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.

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Messages: 87

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
Messages: 8

of course you can access database using jsp(scriptlet )
Ankit Garg
Bartender

Joined: Aug 03, 2008
Messages: 6371

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...

SCJP 6.0 98%, SCWCD 5 98%, Javaranch SCJP FAQ, SCWCD Links
Bear Bibeault
Author and opinionated walrus
Sheriff

Joined: Jan 10, 2002
Messages: 36592

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.

This message was edited 1 time. Last update was at by Bear Bibeault


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
David Newton
Author
Bartender

Joined: Sep 29, 2008
Messages: 6852

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

Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Messages: 2316

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?

How to Ask Good Question|EL or JSTL problem|Tomcat Faq
Bear Bibeault
Author and opinionated walrus
Sheriff

Joined: Jan 10, 2002
Messages: 36592

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).


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
David Newton
Author
Bartender

Joined: Sep 29, 2008
Messages: 6852

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.

Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Servlets
 
RSS feed
 
New topic
hibernate profiler