Upload
briana
View
26
Download
2
Embed Size (px)
DESCRIPTION
CS491B. Technology Comparison between JSP and Rails. By Kwan Shing Yuen. Description. Comparison two programming languages by creating online store web site Java (OO language) and JSP(J2EE) Ruby (Scripting language) and Rails. JSP version. ( JSP version) Programming Language:Java 1.5 - PowerPoint PPT Presentation
Citation preview
Technology Comparison between JSP and Rails
By Kwan Shing Yuen
CS491B
Description
• Comparison two programming languages by creating online store web site
• Java (OO language) and JSP(J2EE)
• Ruby (Scripting language) and Rails
JSP version
• ( JSP version)• Programming Language: Java 1.5• Development tool: Sun J2EE™
Development Kit 5.0• Integrated Development
Environment: TextPad 4.7.3 32-bit
• Development Platform: Microsoft Windows XP
• Web Server: Tomcat ( port 8080 )• Database: MYSQL
Rails version
• ( Rails version)• Programming Language: Ruby (ruby1.8.2-15)• Development tool: Ruby on Rails framework• Integrated Development
Environment: TextPad 4.7.3 32-bit Edition
• Development Platform: Microsoft Windows XP • Web Server: WEBrick 1.3.1 ( port
3000 )• Database: MYSQL
Book Store Feature
• Book search
• Shopping Cart
• Check Out
• Login ( admin )
• Pending and Shipped Order List
Database
Database (Cont.)
Database (Cont.)
Database (Cont.)
Structure overview
Software Architecture
•MVC–Model
–View
–Controller
JSP
• Models– User.java– MyBook .java, MyBooks.java– CartItem.java, CartItem.java
• Views– userM.jsp– adminM.jsp– MyCart.jsp
………• Controller
– Book_Controller.java
Rails
• Models– Book.rb– Order.rb– Cart.rb
• Views– Search.rhtml– Display_cart.rhtml– List.rhtml
………….
• Controller– book_Controller.rb, admin_Controller.rb,
login_Controller.rb
Syntax
Variable
In Java: MyBook temp = new MyBook()
In Ruby: @temp ( we don’t need to specific the type, it can be a object)
eg. @temp = Book.new
Syntax (Cont.)
• Parameter
• In JSP: req.getParameter("id") -> in a String type
• In Rails: params[:id] -> can be any type
Syntax (Cont.)
HyperLink
In JSP: <a href="show.jsp?id=3">ISBN</a>
In Rails: <%= link_to @bookss.ISBN, :action => "show", :id => @bookss.id %>
Development
• JSP has to code line by line
• JSP has more code in getting data from database
Rails
• It has a scaffold autogenerated
• Less code of getting data in MYSQL– Auto mapping to the database
• Create table books ( id int …………..
• Book.rb– class Book < ActiveRecord::Base…….
– ……
– ……
– end
DEMO
• >rails depot
• create table products( id int not null auto_increment, name varchar(10) not null, primary key(id));
• database connection • > ruby script.generate scaffold Product Admin
Search in database• Search in Database:• In JSP:
• //• Result rs= stmt.executeQuery("select * from books where id = 2");• while( rs.next() )• {• int id = rs.getInt(“id”);• }• //• //• Result rs= stmt.executeQuery("select * from books where isbn = ‘16349827’");• while( rs.next() )• {• String isbn = rs.getInt(“isbn”);• }• //
Search in database
• In Rails:
• @id = 2
• book = Book.find(@id)
• @ISBN = 16349827
• @bookss = Book.find_by_ISBN @ ISBN
JSP and RailsDemo