aspose file tools*
The moose likes JSP and the fly likes JSP two pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP two pages" Watch "JSP two pages" New topic
Author

JSP two pages

Ivan Bisevac
Ranch Hand

Joined: Jan 04, 2010
Posts: 48

I have to write to pages in JSP to show to professor that i know to search some database (for example northwind from access) and to click on 1 record and then opens second JSP page for selected record and from that page to show report for that selected record (for example for one customer). I am new to JSP but not to servlets and could you help me with this?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

All the work should be done in Java classes, not JSP. JSP should only be used to show the final results.

In other words, if you find yourself starting to put java code into a JSP, you are doing it wrong.

So get your Java classes written to perform all the database and other stuff, and then let us know what problems you are having showing results in the JSPs.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ivan Bisevac
Ranch Hand

Joined: Jan 04, 2010
Posts: 48

Bear Bibeault wrote:All the work should be done in Java classes, not JSP. JSP should only be used to show the final results.

In other words, if you find yourself starting to put java code into a JSP, you are doing it wrong.

So get your Java classes written to perform all the database and other stuff, and then let us know what problems you are having showing results in the JSPs.

Yout mean that i have to write servlet class? And after that to write jsp? I worked with servlets but with jsp never. Can you explain me more..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Read this article.
Ivan Bisevac
Ranch Hand

Joined: Jan 04, 2010
Posts: 48

I found example on http://www.roseindia.net/servlets/search.shtml and did some changes and now it is not working. Here is the code:




Search.java








what is doing command al.add(). Maybe this example is for searching and presenting just 1 record from database?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Ugh! Java code in a JSP? In 2010?

I'd suggest using more up-to-date examples.
Ivan Bisevac
Ranch Hand

Joined: Jan 04, 2010
Posts: 48

Bear Bibeault wrote:Ugh! Java code in a JSP? In 2010?

I am beginner in jsp and don't know why you say this.


Can you give me those examples or links to them. I just need search form and when search is complete to display results on second page. Then from second page to generate report. Can you give me those examples?
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Did you read the article Mr.Bear gave to you?
It should give a clear idea what he is trying to tell you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Ivan Bisevac wrote:I am beginner in jsp and don't know why you say this.

As a beginner, it's important to not learn bad practices to begin with. Putting Java code in a JSP has been a discredited practice for over 8 years.

You want to avoid reference that use Java scriptlets. Modern JSP uses JSTL (JSP Standard Tag Library) and the EL (Expression Language).

You might also benefit from reading these articles: The Secret Life of JSPs and The Front Man (again).
Ivan Bisevac
Ranch Hand

Joined: Jan 04, 2010
Posts: 48

Ok, i will read this articles tomorow. Is there any book for this with examples?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Any modern JSP book will cover JSTL and EL.
Ivan Bisevac
Ranch Hand

Joined: Jan 04, 2010
Posts: 48

Ok, i read book Core servlets and jsp pages and now am familiar with jsp. But now i have some questions.
After i get data from database do i put it in html table or there is a data grid in JSP? How to open one record in another page? For example i write sql query that gives me all employees with starting letter 'B' in name. I get some data and display it. How to make that customer make choice of just one employee and after employee is selected how to display result in another page? I don't need code just some advices. Thanks..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Ivan Bisevac wrote:After i get data from database do i put it in html table or there is a data grid in JSP?
JSP is just a templating technology that helps you create the HTML pages. Any "data grid" will need to be rendered in HTML, JavaScript and CSS. There are 3rd party tag libraries that can help you do this (though I'm not personally impressed by any of them).

How to open one record in another page?
Based on what? A mouse click? If so, get the primary key from the clicked element and submit a request that goes through the whole process of fetching the data and displaying it.

The articles I referenced show this cycle.

Ivan Bisevac
Ranch Hand

Joined: Jan 04, 2010
Posts: 48

Bear Bibeault wrote:
Ivan Bisevac wrote:After i get data from database do i put it in html table or there is a data grid in JSP?
JSP is just a templating technology that helps you create the HTML pages. Any "data grid" will need to be rendered in HTML, JavaScript and CSS. There are 3rd party tag libraries that can help you do this (though I'm not personally impressed by any of them).

How to open one record in another page?
Based on what? A mouse click? If so, get the primary key from the clicked element and submit a request that goes through the whole process of fetching the data and displaying it.

The articles I referenced show this cycle.



Witch 3rd party library are those? Where i could find some info for that..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

I'd try google.
Ivan Bisevac
Ranch Hand

Joined: Jan 04, 2010
Posts: 48

Bear Bibeault wrote:I'd try google.


I found some libraries but i asked for your experience. that's why i am here on forum.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

I've already said that I'm not impressed with any of them, so there isn't one I'd recommend.

I just do it myself. Creating an HTML table in JSP isn't at all hard, and I use jQuery on the client side to instrument the table with the appropriate behaviors.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP two pages