• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java code in JSP  RSS feed

 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I written java code in JSP to display data. I know it is bad practice. Actually my Business-service communicates with DB and returning data in the form of MAP. I don't have beans Because the fields in DB is dynamically changing. So, for now I'm retrieving Data by writing Java code in JSP. Is there any other way to display data without writing java code in JSP?

Thanks:
Ramakrishna K.C
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the modern (as of 2002) way to display data in a JSP is via the JSTL (JSP Standard Tag Library) and the EL (Expression Language).
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that means, to display I've to use JSTL/EL tags which gives some of the familiar tags like "for" loop, "if" "else" tags. etc., right?
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, exactly.
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually in my service.class multimap is returning with data. I've to display that multimap data in JSP.

service.class



How to catch above "maps" in JSP? To catch this Multimap "maps", I've to create instance of the service.class. like this,



If I do this, Is this right way?
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My actual problem is, I want to display data in JSP which is returned by Retrieve() method in service.class, which returns Multimap. I don't/can't create bean, Because, I've two parts in my app. 1st webApp and 2nd core java. From UI(webApp) user click the button and request sent to Core-java project through Web-services. In core-java, the data will be stored into DB(Hypertable). Now, Data is stored. Now, I want to display that data in JSP(webApp). So, I don't have bean. When user want to see data, then service.class contains methos which returns multimap. I want to display that data in JSP. How to this?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I do this, Is this right way?

No, you should read up on JSTL. The JspFaq points to a 4 part series of introductory articles in case you're unfamiliar with it (you can omit part 4).

I want to display that data in JSP. How to this?

Data to be used by JSPs is generally passed to it as a request attribute by a servlet (or whatever control layer your web framework has in place).
 
Ramakrishna Udupa
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ulf Dittmer Please see my last post and suggest me how to display in that case.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you familiar with MVC, request attributes and JSTL? That is prerequisite knowledge for implementing well-structured Java web apps. If not, start by working through a comprehensive tutorial on that, like the Head First Servlets & JSP book or something similar in scope.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!