Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to write javascript in servlet?  RSS feed

 
Rahul Surati
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends,

I want to write javascript in servlet..

how could I write it.. ??
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RAHUL SURATI, you have already been asked once, please adjust your display name to be not all uppercase. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same way that write any of the other markup in a servlet: by emitting it as strings to the output stream.

It's not a good way to do things. Why are you not using JSPs to render the HTML/JavaScript markup?
 
Rahul Surati
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The same way that write any of the other markup in a servlet: by emitting it as strings to the output stream.

It's not a good way to do things. Why are you not using JSPs to render the HTML/JavaScript markup?



I want to put presentaton logic and bussiness logic different .. so, I used servlet....

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul Surati wrote:I want to put presentaton logic and bussiness logic different .. so, I used servlet....

That makes no sense. How does not using a JSP for the HTML markup achieve this?

You may be interested in this article that explains modern web application structure.
 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul

You may want to have a look at MVC architecture. To put it simply, put your 'business logic' in servlet (if you don't want to put in some other 'model' class) and send it to JSP, which will form the presentation layer.

I guess you wanted to avoid business logic in JSP and hence decided to put presentation logic in servlet, but as Bear said it is not correct too!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly. Putting Java in a JSP is a bad practice, but so is putting HTML into Java! Use each tool, servlets and JSP, to their best advantage!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!