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

Can we write new class/innerclass inside jsp page?  RSS feed

 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am just for curiosity asking this question.:-
What things from java we can write inside jsp page(between scriptlet)?
Can we write complete class or innerclass inside jsp page?

Please tell me.
Thanx.
Pras
 
Prasad Babu
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

No one stop you to write inner classes in JSP

With regards,
Prasad
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can u please tell me how to write it in JSP?
thanx
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Prashant Tiwari:
hi,
can u please tell me how to write it in JSP?
thanx


Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.

In particular please see: UseRealWords

Abbreviations such as "u" or "ur" in place of "you" and "you are"
or "you're" confound language translation software making it hard
for our non-English speaking members to read your posts
Again, welcome to JavaRanch and good luck with your question.
-Ben

Java's concept of inner classes is not really a JSP issue so you're probably not going to find someone willing to take the time to explain them to you here. I doubt I, or the other moderators of this forum, will stand for a long discussion on inner classes here.

If you already know how to write one, try it in your JSP and see how it works for you.
If you don't already understand inner classes ask about them in one of the Java In General forums or pick up a book on core Java. (Bruce Ekel's 'Thinking In Java' does a good job explaining them).

Personally, I can't imagine a case where it would be helpful to do this.
JSP has evolved to the point where the accepted best practice is to move all but the view rendering code out of the actual JSP, into servlets and beans.
I couldn't think of a better way to profane this concept.
 
sudhir gandala
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u can write it in this way
<%
java code u want to write
%>
{%>
html r jsp code
<%}%>
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ben Souther,
sorry for my language mistakes.
Actually I am asking this question here, because in one of my interviews on JSP, Interviewers asked me this question of inner clases. I am not asking this just for fun or just for getting maxximum from this forum.

Prashant.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs get compiled into servlets, which are Java classes.
There is no technical reason why it wouldn't work, that I know of.

As I mentioned earlier, these days, the recommended best practice for server side Java apps is to do all the real heavy lifting in servlets and beans.
Then forward to the JSP for formatting of the results.

In a Model1 app with everything being done being done in the JSP inner classes could be used to spawn new threads for something like a bulk mailer which would need to return immediately while the emails are busy being sent in the new thread. It's ugly and I'm grateful that such things are not necessary in MVC apps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!