Transcript
Page 1: Technology Comparison between JSP and Rails

Technology Comparison between JSP and Rails

By Kwan Shing Yuen

CS491B

Page 2: Technology Comparison between JSP and Rails

Description

• Comparison two programming languages by creating online store web site

• Java (OO language) and JSP(J2EE)

• Ruby (Scripting language) and Rails

Page 3: Technology Comparison between JSP 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

Page 4: Technology Comparison between JSP and Rails

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

Page 5: Technology Comparison between JSP and Rails

Book Store Feature

• Book search

• Shopping Cart

• Check Out

• Login ( admin )

• Pending and Shipped Order List

Page 6: Technology Comparison between JSP and Rails

Database

Page 7: Technology Comparison between JSP and Rails

Database (Cont.)

Page 8: Technology Comparison between JSP and Rails

Database (Cont.)

Page 9: Technology Comparison between JSP and Rails

Database (Cont.)

Page 10: Technology Comparison between JSP and Rails

Structure overview

Page 11: Technology Comparison between JSP and Rails
Page 12: Technology Comparison between JSP and Rails

Software Architecture

•MVC–Model

–View

–Controller

Page 13: Technology Comparison between JSP and Rails

JSP

• Models– User.java– MyBook .java, MyBooks.java– CartItem.java, CartItem.java

• Views– userM.jsp– adminM.jsp– MyCart.jsp

………• Controller

– Book_Controller.java

Page 14: Technology Comparison between JSP and Rails

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

Page 15: Technology Comparison between JSP and Rails

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

Page 16: Technology Comparison between JSP and Rails

Syntax (Cont.)

• Parameter

• In JSP: req.getParameter("id") -> in a String type

• In Rails: params[:id] -> can be any type

Page 17: Technology Comparison between JSP and Rails

Syntax (Cont.)

HyperLink

In JSP: <a href="show.jsp?id=3">ISBN</a>

In Rails: <%= link_to @bookss.ISBN, :action => "show", :id => @bookss.id %>

Page 18: Technology Comparison between JSP and Rails

Development

• JSP has to code line by line

• JSP has more code in getting data from database

Page 19: Technology Comparison between JSP and Rails

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

Page 20: Technology Comparison between JSP and Rails

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

Page 21: Technology Comparison between JSP and Rails

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”);• }• //

Page 22: Technology Comparison between JSP and Rails

Search in database

• In Rails:

• @id = 2

• book = Book.find(@id)

• @ISBN = 16349827

• @bookss = Book.find_by_ISBN @ ISBN

Page 23: Technology Comparison between JSP and Rails

JSP and RailsDemo


Recommended