quan’s posterous

 

[linux] install kernel-devel package

- Check your kernel type:
uname -r
- If you are running the smp kernel:
yum install kernel-devel
- If you are running the xen kernel:
yum install kernel-xen-devel
- If you're running the PAE kernel:
yum install kernel-PAE-devel
- Check /usr/src directory

Filed under  //   CentOS   kernel   linux  

Comments [0]

[spring 10] Integrating the Web Application with the Persistence Layer

- Modify service layer 

modify the SimpleProductManager and add a reference to a ProductDao
'springapp/service/SimpleProductManager.java'

- remove the productManager configuration and the list of products from the springapp-servlet.xml
- configure the service layer in its own application context file 'applicationContext.xml'.
It will be loaded via a servlet listener that we will define in 'web.xml'

- 'springapp/web/WEB-INF/applicationContext.xml'

- using AOP (Aspect Oriented Programming) in the form of a transaction advice and an AspectJ pointcut to define where the transactions should
be applied

The pointcut applies to any method called on the ProductManager interface. The advice is a transaction advice that applies to methods with a name starting with 'save'.
- using the DBCP connection pool

- add lib spring-aspects & dbcp in dom.xml

- run & enjoy

Click here to download:
springapp.rar (13 KB)

Filed under  //   java   Spring   web  

Comments [0]

[spring 9] Implementing Database Persistence -JDBC

- Using mySQL 

- Create database startup script
'springapp/db/create_products.sql'

'springapp/db/load_data.sql'

Run scripts and load test data

- Create a Data Access Object (DAO) implementation for JDBC
'springapp/repository/ProductDao.java'

'springapp/repository/JdbcProductDao.java'
+ using Spring's JDBC, don't have to worry about opening and closing
the connection or any statements, won't have to catch any exceptions
+ SimpleJdbcDaoSupport provides SimpleJdbcTemplate

+ getSimpleJdbcTemplate().query: provide the SQL statement and a
class that can handle the mapping between the ResultSet and the
Product class
+ ProductMapper implement ParameterizedRowMapper: mapRow map the
data from each row into a class
+ MapSqlParameterSource allows us to use named parameters instead of
the typical "?"

- Add a private field named 'id' complete with setters and getters to Product.java

- Implement tests for JDBC DAO implementation
Add Spring test framework

JdbcProductDaoTests.java

+ extending AbstractTransactionalDataSourceSpringContextTests --> load application context (test-content.xml)
+ onSetUpInTransaction: clear table & load data test, rolled back once the test finishes
test/resources/test-context.xml

test/resources/jdbc.properties

- Run unit test

Click here to download:
springapp.rar (14 KB)

Filed under  //   java   jdbc   Spring   web  

Comments [0]

[spring 8] Developing the Web Interface - add form

we add a form that will allow the user to enter a percentage price increase 

'springapp/web/WEB-INF/jsp/priceincrease.jsp'

'springapp/service/PriceIncrease.java'

'springapp/service/PriceIncreaseValidator.java'

add an entry in the 'springapp-servlet.xml' file to define the new
form and controller
 + define objects for commandClass and validator
 + formView and a successView
'springapp/web/WEB-INF/springapp-servlet.xml'

controller for this form
 + onSubmit(..) method: get command object
'springapp/web/PriceIncreaseFormController.java'

adding some messages to the 'messages.properties' resource file
'springapp/web/WEB-INF/classes/messages.properties'

add a link to the price increase page from the 'hello.jsp'

re--deploy & run

Click here to download:
springapp.rar (11 KB)

Filed under  //   java   Spring   web  

Comments [0]

[spring 7] Developing the Web Interface

Add reference to business logic in the controller

- rename HelloController to InventoryController and the HelloControllerTests to InventoryControllerTests
- modify the InventoryController to hold a reference to the ProductManager class
- add code to have the controller pass some product information to the view.
'/springapp/web/InventoryController.java'

Modify the view to display business data and add support for message bundle
- <c:forEach/>: displays product information
- <fmt:message/>: pulls the text to display from a provided 'message' source
'springapp/web/WEB-INF/jsp/hello.jsp'

Add some test data
add a SimpleProductManager to our configuration file and to pass that into the setter of the InventoryController
put the data in 'springapp-servlet.xml' (remember to rename the reference to HelloController to InventoryController)
'springapp/web/WEB-INF/springapp-servlet.xml'

add the 'messageSource' bean entry
'springapp/web/WEB-INF/classes/messages.properties'

Rebuild & run app

Click here to download:
springapp.rar (9 KB)

Filed under  //   java   Spring   web  

Comments [0]

[spring 6] Developing the Business Logic

- Business:
The application we will be building from scratch over the course of this tutorial is a very basic inventory management system.
In our inventory management system, we have the concept of a product and a service for handling them. In particular, the business has requested the ability to increase prices across all products.
The validation rules for price increase are:
 The maximum increase is limited to 50%.
 The minimum increase must be greater than 0%.
Find below a class diagram of our inventory management system.
- Create Product class
Let's also make it Serializable, not necessary for our application, but could come in handy later on when we persist and store its state.
'springapp/domain/Product.java'

Create the ProductManager
It contains two methods:
  increasePrice(): increases prices for all products
  getProducts(): retrieving all products
'springapp/service/ProductManager.java'
SimpleProductManager class that implements the ProductManager interface
'springapp/service/SimpleProductManager.java'
- SimpleProductManagerTests.java

Click here to download:
springapp.rar (7 KB)

Filed under  //   java   Spring   web  

Comments [0]

[spring 5] Developing and Configuring the Views and the Controller

- using the JSP Standard Tag Library (JSTL) 

pom.xml
 

- create the header file for inclusion in all the JSPs we create.
'springapp/web/WEB-INF/jsp/include.jsp'

- update 'index.jsp' to use JSTL, redirecting to our front Controller.
'springapp/web/index.jsp'

- Move 'hello.jsp' to the 'WEB-INF/jsp' directory. Using the JSTL tag to output variable retrieved from the model
'springapp/web/WEB-INF/jsp/hello.jsp'

- Update the location of the JSP in our controller.
update our unit test class first

test fail

- Update HelloController

- Test again
- Run http://localhost:8084/springapp/ --> redirect to /hello.htm
- Decouple the view from the controller
map to the view using a logical name, remove prefix and suffix
'springapp/web/WEB-INF/springapp-servlet.xml'

update the view name in the controller test & controller to 'hello'
- test & run again

Click here to download:
springapp.rar (5 KB)

Filed under  //   java   Spring   web  

Comments [0]

[spring 4] maven spring web app on netbeans 6.7

- netbeans > new maven web app
- run index.jsp to see 'Hello World!' message

- Add spring web fw to project

  add to pom.xml

  add to springapp2/web/WEB-INF/web.xml
 + autoload Dispatcher at startup
 + URL with an '.htm' extension be routed to the 'springapp' servlet (the DispatcherServlet)

- Add new file springapp2/web/WEB-INF/springapp-servlet.xml


- Create the Controller
com.mycompany.springapp2.web.HelloController
- Test Controller
HelloControllerTests.java

- Create the View
'springapp2/web/hello.jsp':
- Compile, deploy & run the application: http://localhost:8084/springapp2/hello.htm

Click here to download:
springapp2.rar (4 KB)

Filed under  //   java   Maven   Spring  

Comments [0]

Turn on address autocomplete in Firefox

- enter about:config in the address bar
- right-click anywhere on the list and select New > Boolean : browser.urlbar.autoFill true

Filed under  //   autocomplete   Firefox  

Comments [0]

[php] curl login

using through PHP 5 objecte oriented encapsulation

Filed under  //   curl   php  

Comments [0]