2013年11月3日 星期日

免費英文學習資源

1. Voicetube-看影片學英語

voicetube

全臺最大的看影片學英語社群,每日更新影片,提供最多最優質的英文學習內容。

包括TED Talks、TED-Ed 教育、CNN Student News、看卡通學英文、聽音樂學英文、

電影片段、電玩、英文技巧學習等超過4,000部英語學習影片。

其特色包括影片字幕導讀、重覆播放功能、字幕跟讀功能、學習進度追蹤、

全文字典單字查詢收藏、螢光標示佳句等。

 
2. BCC learning English

BCClearningEnglish

由英國廣播公司製作的免費英語教學網站,內容涵蓋聽說讀寫四方面,

結合時事、科技、人文,且有文法及片語介紹,

所有文章皆包含MP3語音檔、PDF講稿文字與簡單問答,適合想熟悉英國腔者。

 

3. CNN Student News
CNN

美國 CNN 電視台將每天發生的重大新聞濃縮成十分鐘,並附上 PDF 檔的新聞稿,

讀者僅需每天只要花十分鐘聽英文,即可增進英文能力並了解國際動脈。

 

4. TED
TED

TED分別代表的是科技 (technology)、娛樂 (entertainment)、設計 (design),

集結全世界各領域,對未來充滿熱情的講者,透過每場18分鐘的演講,

傳達優秀的思想可以改變人們的看法,使人們反思自己行為的理念。

TED提供英文演講內容、字幕及逐字稿,部分附有中文字幕。

 

5. CC Prose
CCProse

此影音頻道沒有華麗的畫面,只是很簡單的把書本念給您聽,

同時打上字幕,讓您可以邊聽邊讀。

2013年10月18日 星期五

在Windows PHP安裝ffmpeg-php


關於在Windows內使用ffmpeg-php, 網路上有很多方法, 
e.g. myownserver 在 How to install ffmpeg-php for Windows Apache HTTP Server 介紹安裝在xampp的方法, 從 http://sergey89.ru/files/ffmpeg-php/ 下載ffmpeg-php-5.3-win32-all.zip後, 逐步安裝後再用一支程式測試.
但是我是用AppServ + PHP 5.3.5 所以我用的方法

取得 ffmpeg-php
php.ini
首先解開之後, 先把 php_ffmpeg.dll 複製到 php5/ext內; php.ini 增加 一行 
extension=php_ffmpeg.dll

http.conf
我不喜歡複製到 System32 , 所以我在 http.conf 增加下列幾行:
#php 5.3
之前就有的
Loadfile "C:\AppServ\php5\php5ts.dll"
Loadfile "C:\AppServ\php5\libpq.dll"
 這次增加的
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avcodec-52.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avcore-0.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avdevice-52.dll"                                                 
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avfilter-1.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avformat-52.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avutil-50.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\pthreadGC2.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\swscale-0.dll"

phpinfo測試

測試ffmpeg.php
結果畫面

done.

PHP在Windows環境下執行

名詞解釋

首先說明VC6及VC9:

VC6 : 就是使用 Visual Studio 6 compiler 這個編譯器編譯的.
VC9 : 就是用微軟的 Visual Studio 2008 compiler 編譯的.
TS : Thread Safe 線程安全, 執行時會進行線程(Thread)安全檢查, 以防止有新要求就啟動新線程的CGI執行方式而耗盡系統資源
NTS : Non Thread Safe 非線程安全, 在執行時不進行線程(Thread)安全檢查
ISAPI(Internet Server Application Programming Interface)執行方式是以DLL動態庫的形式使用, 可以在被用戶請求後執行, 在處理完一個用戶請求後不會馬上消失, 所以需要進行線程安全檢查, 這樣來提高程序的執行效率.
FastCGI : 執行方式是以單一線程來執行操作, 所以不需要進行線程的安全檢查, 除去線程安全檢查的防護反而可以提高執行效率.

 

PHP 官網說明:

Which version do I choose?

If you are using PHP with Apache 1 or Apache2 from apache.org you need to use the VC6 versions of PHP
If you are using PHP with IIS you should use the VC9 versions of PHP
VC6 Versions are compiled with the legacy Visual Studio 6 compiler
VC9
Versions are compiled with the Visual Studio 2008 compiler and have improvements in performance and stability. The VC9 versions require you to have the Microsoft 2008 C++ Runtime (x86) or the Microsoft 2008 C++ Runtime (x64) installed

Do NOT use VC9 version with apache.org binaries
 

Thread Safe線程安全

Linux 使用多進程(process)不同於Windows採用的多線程(Thread)的工作模式; 而CGI是以Linux的多進程所設計的, 所以如果在IIS 的 PHP 使用 CGI 模式, 每次HTTP的請求PHP都需重新加載及缷載, 所以速度慢。
IIS另外一個選擇是使用ISAPI的方式(早期的ASP.NET也是用這種方式), 因為php5nsapi.dll是用多線程設計的(Thread safe),符合Windows多線程的設計,速度較快。
但是在選擇PHP Extension時就要注意, 必須使用TS(Thread safe)的版本, 否則會搞垮IIS. 但是大部份的PHP_Extension都是針對Linux的多進程設計的.
為了在Windows IIS兼顧速度及線程安全, 微軟推出FastCGI; FastCGI保留了CGI的工作模式, 又提供一個pool機制管理重覆使用的進程, 確保non-thread-safe的libraries可以正常執行。
 

結論

使用ISAPI方式, php extension 就要用Thread Safe的版本; 如果使用FastCGI就不用Thread Safe(non-thread-safe)了,效能還更好呢.
 
 

2013年9月26日 星期四

用Maven執行Java程式

Eclipse 用習慣了,IDE提供方便的操作,也讓我變笨了.

在命令列使用maven要執行JAVA console 程式,有一個好用的plug-in :  exec-maven-plugin

 

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<mainClass>com.clickap.test.NeoSpring</mainClass>
</configuration>
</plugin>
 
使用mvn exec:java 命令就可以執行了
mvn-exec-java

 


提示1


如果你跟我一樣對 pom.xml的schema不熟,不知道plugin要放在哪裡, 這裡有完整的結構.

<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<mainClass>com.clickap.test.NeoSpring</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
 

提示2


如果程式需要加*參數*

<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.clickap.test.NeoSpring</mainClass>
<arguments>
<argument>argument1</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
 
 

2013年9月24日 星期二

影像處理的日子

這張圖很熟悉吼~

lenna

本尊出現在 IS&T 50週年慶

無意中找到這篇在交大的網站上  http://www.csie.nctu.edu.tw/~zlxuan/lena/lenna.html 

是不是勾起了很多回憶 Smile

2013年9月13日 星期五

Maven專案在Eclipse Run on Server

想在Eclipse 操作Maven 2 專案, 現在有比較方便的外掛  :  M2E – WTP
內置圖片 4
M2E-WTP
目前是 1.0.0版 http://wiki.eclipse.org/M2E-WTP/New_and_Noteworthy/1.0.0

0.安裝方法
我直接用 Install New Software方式安裝 網址 : http://www.eclipse.org/m2e-wtp/download/
勾選 m2e 及 m2e-wtp 兩項.
因為我的Helios已經安裝M2E 1.4版了, 所以只要選取 m2e-wtp 這項即可.

1.安裝後, 新增Maven專案


2.在Filter用關鍵字 webapp
選取org.apache.maven.archetypes

3.給命名空間(Group Id)及專案名稱(Artifact Id)


神奇的事發生了, 在專案名稱按右鍵,選取Run on Server
你已經設定好的Tomcat
執行結果

太好了, 以後可以用熟悉的方式 Eclipse 在  Maven 的 Web專案用  Run on Server 了.

要注意的是 M2E-WTP 跟 m2eclipse-wtp 不能同時安裝.

參考自http://www.eclipse.org/m2e-wtp/download/

2013年9月3日 星期二

硬碟空間不夠?

當然清除回收桶, 新增移除程式一定有幫助的.
CCleaner , Sweep 之類的軟體也不錯(google就找到一堆了)
我要介紹的是 SpaceSniffer 如圖


SpaceSniffer
啟動後等一下, 它後幫你把各個資料夾所佔的空間圖形化, 是不是一目了然?
這裡可以下載

分享我的經驗(Windows7)
ProgramData\Microsoft\Search\Data 高達12G, 使用控制台->索引->進階 按下重新索引(Rebuild)後剩下84MB.
ProgramData\Microsoft\OEMOffice14 直接砍掉
ProgramData\Microsoft\HelpLibrary 直接砍掉, 但是在 C:\Program Files\Microsoft Help Viewer\v1.0\HelpLibManager.exe.config 加上一行 <add key="FirstTimeRun" value="True" /> , 下次執行時再詢問.

Java檢查記憶體使用情形

主要是因為出現了 java.lang.OutOfMemoryError: Java heap space

 

JDK6以後附了 Java VisualVM (jvisualvm.exe) 在bin的目錄內, 這裡有詳細說明;

1.Overview

先把你要檢查的Java執行起來, 然後打開jvisualvm(如圖), 在左邊Applications內點選你的JVM(我是用OC4J), 就可以在Overview看到JVM的運作環境及設定的參數.

 

jVisualVm

因為要測heap , 你會發現上圖我有加了一些參數, 這裡說明一下:

-XX:+HeapDumpOnOutOfMemoryError   在出現 OutOfMemoryError 時會產生一個 hprof的檔案(e.g. java_pidxxxxx.hprof, 預設會寫在JVM所在路徑, 也可以加 -XX:HeapDumpPath=yourpath ), 方便我們檢查記憶體使用的情況; 使用方法請看這裡 .

hprof 檔可以用 Eclipse memory analyzer (mat, http://www.eclipse.org/mat/ ) 打開來看, 建議載 Stand-alone Eclipse RCP Applications 的版本比較方便(如圖)

mat-1

-Xms512m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=256m  這幾個參數相信大家都很熟悉, 我就不多說了; 只是 Permanent Size 本來大家都說很小(只要64m), 可是經過 jVisualVM測過, 我發現我的 AP 一下就超過了, 所以我把它改為 128m 起跳; heap size 也把它加到 512m.

 

 

2.切換到Monitor還有圖(chart)

jVisualVm chart

 

接下來就是觀察記憶體使用情形, 然後跟著調整及修正了.

參考自 http://javarevisited.blogspot.sg/2011/09/javalangoutofmemoryerror-permgen-space.html

2013年9月2日 星期一

Difference between instance class and local variables in Java

參考自 http://javarevisited.blogspot.tw/2012/02/difference-between-instance-class-and.html 

There are lot of differences between instance variable, class variable and local variable in Java and knowing them will help you to write correct and bug free Java programs. Java is full featured programming language and provides different kind of variables like static variable also called Class variable since it belongs to whole Class, non static also called instance variable and local variables which varies in scope and value. Thank god Java doesn't have any register variable or auto scope like C otherwise it would have so much detail to remember. static variables are common source of error in may multi-threadedjava program and does require a bit of carefulness while using it. On the other hand instance variable and local variable has less sharing visibility than static variable.

Instance Variable vs Class Variable in Java

let's first see difference between instance variable and class variable also known as non static vs static variable in java. Instance variable are per instance (object) basis. If you have 5 instance of one class you will have five copies of instance variable. these are also referred as non static variable and initialized when you create instance of any object using new() operator or by using other methods like reflection e.g. Class.newInstance(). On the other hand Class variables are declared using static keyword and they have exact same value for every instance. static or class variable are initialized when class is first loaded into JVM memory unlike instance variable which initialized when instance is created. Static variables are similar to global variable in C and can be used to store data which is static in nature and has same value for all instance, but at same static variable also cause subtle concurrency bugs if updated by multiple threads. you can read more about static keywords in my post secrets of static keyword in Java .

Instance variable vs local variable in Java

Now let's see difference between instance variable and local variable.local variables are local in scope and they are not visible or accessible outside there scope which is determined by {} while instance variables are visible on all part of code based on there access modifier e.g. public , private or protected.only public can be accessed from outside while protected and private can be accessed from subclass and class itself. Access modifier can not be applied to local variable and you can not even make them static. only modifier which is applicable to local variable is final and only final local variables are visible inside anonymous class. value of instance variable is limited to instance, one instance can not access value of other instance in Java.

Best practices related to local, instance and static variable in Java

Its good to know some of the best practices related to declaration and use of Variables in Java while learning differences among different type of variable in Java:

  1. Always name your variable as per Java Bean naming convention.
  2. By default give private access to your member variables (both static and instance) and provide more access step by step e.g. from private to protected to package to public. This way you will be following encapsulation principle.
  3. Always declare local variable where you use instead of declaring it on top of method or block.
  4. Don't hide instance or static variable by giving same name to local variable. this may result in subtle programming bugs.
  5. Be consistent with your variable naming convention don't mix different convention from different language e.g. some programming language use first word to denote type of variable e.g. bExit to denote boolean Exit variable or iNumber to denote integer Number variable. Though they are good but mixing simple names as per Java Bean naming convention with this will only lead confusion.
That’s all on difference between local vs instance vs class variable in Java. correct understanding of there scope, value and accessibility is key to write java program.

2013年8月29日 星期四

Window內開啟指定JDK環境懶人法

我是懶人.

我的開機環境是JDK5, 但是也有JDK6的專案要執行, 常常換來換去很麻煩.

 

1.首先建立一個bat, 取名 JDK6.bat, 換成自已的JDK路徑

@echo off
cd /D %1
Set JAVA_HOME=C:\JDK\jdk1.6.0_25
Set PATH=C:\JDK\jdk1.6.0_25\bin;%PATH%

 

2.建立一個reg檔, 替換自己JDK6.bat的路徑

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\cmd_jdk16]
@="Open JDK1.6 Command Prompt Here"

[HKEY_CLASSES_ROOT\Directory\shell\cmd_jdk16\command]
@="cmd.exe /k \"C:\\yourpath\\JDK6.bat \"%L\"\""

 

3.這樣就可以輕鬆切換JDK環境了

JDK6

2013年8月16日 星期五

RedHat el5 安裝Mysql5.5

參考自 http://stackoverflow.com/questions/9361720/update-mysql-version-from-5-1-to-5-5-in-centos-6-2

節錄內容

To list Old MySql

yum list installed | grep -i mysql

To remove Old MySql

yum remove mysql mysql-*

Remi Dependency on CentOS 6 and Red Hat (RHEL) 6

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Install MySQL server

yum --enablerepo=remi,remi-test install mysql mysql-server

To list New MySql

yum list installed | grep -i mysql

start MySql server


/etc/init.d/mysqld start ## use restart after update

OR


service mysqld start ## use restart after update
chkconfig --levels 235 mysqld on

Last

mysql_upgrade

Now my MySql version is 5.5.32

Ref:


http://www.webtatic.com/packages/mysql55/
http://www.if-not-true-then-false.com/2010/install-mysql-on-fedora-centos-red-hat-rhel/
 
------------------------------
我下的指令
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm –Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
yum --enablerepo=remi,remi-test install mysql mysql-server
/etc/init.d/mysqld
這樣就裝好了, 裝好Mysql後記得去更新password
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h vdb password 'new-password'

或者
/usr/bin/mysql_secure_installation



因為要建立一個DB並從另一台主機連線.
#mysql -u root -p
建一個資料庫
CREATE DATABASE mydatabase DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

給外部連線權限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'連線主機IP ' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON ‘%`.* TO 'root'@'連線主機IP ' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON `%`.* TO `root`@`連線主機IP` IDENTIFIED BY 'password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON moodle.* TO 'root'@'連線主機IP' IDENTIFIED BY 'password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON moodle.* TO 'root'@'連線主機IP' IDENTIFIED BY 'password' WITH GRANT OPTION;
(忘了是哪一個,所以全部貼上)

 done.完成












2013年8月15日 星期四

Juno 沒有Tomcat?

請到 Help -> Install New Software 選擇 http://download.eclipse.org/releases/juno/ , 展開 "Web, XML, and Java EE Development", 安裝 JST Server Adapters及 JST Server Adapters Extensions .

更新後重啟Eclipse 然後安裝Tomcat 跟以前的方式一樣.

2013年8月14日 星期三

hibernate connection 隔夜被斷線的問題

最近因為一個Hibernate + Spring + Quartz  的Web專案,  執行完Quartz Scheduler  的Job後,  隔天早上就出現

SQL Error: 17002, SQLState: null
IO 異常: Connection reset
java.sql.SQLException: 關閉的連線

然後就是一堆
SQL Error: 0, SQLState: null
Already closed.
重覆的錯誤

(hibernate connection close overnight的問題, 隔夜connection中斷問題,或是自動重新連線問題…)

Hibernate官網論壇說到

You should never use Hibernate's built-in connection pooling in production; it is non-scalable and non-fault-tolerant. Instead, use DBCP or C3P0 (or, even better, an application server datasource).

Automatic reconnect from Hibernate to MySQL 提出用C3P0

CrazyTechThoughts 在 Resolve Hibernate connection timeout issue with MySQL server 也提出用 c3p0.testConnectionOnCheckout=true 的方法

StackOverflow也有人問 Hibernate, C3P0, Mysql — Broken Pipe

 

好像只能換Connection pool 的技術了, 但我不想將DBCP改為C3P0, 因為還有大部份舊的hibernate mapping 還在運行, 換了之後不知道還要花多少時間測試.

最後我的解決方式:

在 spring 的設定檔內

<bean>

<property name="validationQuery" value="SELECT 1 FROM DUAL" />
<property name="testOnBorrow" value="true" />

</bean>

因為我用的是OracleDB, 所以用 Select 1 From Dual, 其它資料庫請自行修改.

快一週了,好像還可以, 沒聽到有問題.

ORA-17059: Fail to convert to internal representation

could not read column value from result set 無法轉換為內部方式

這個錯誤原因是:資料庫裡的字段類型與Java裡映射該字段屬性的類型不能對應轉換,例如資料庫裡欄位類型為Varchar2,而Java定義的類型為Long;或者資料裡為Number,而Java定義的對應屬性類型為String。

處理*.hbm.xml大部份都能解決問題.

2013年8月10日 星期六

Organizing an ASP.NET MVC Application using Areas

The MVC pattern separates the model (data) logic of an application from its presentation logic and business logic. In ASP.NET MVC, this logical separation is also implemented physically in the project structure, where controllers and views are kept in folders that use naming conventions to define relationships. This structure supports the needs of most Web applications.
However, some applications can have a large number of controllers, and each controller can be associated with several views. For these types of applications, the default ASP.NET MVC project structure can become unwieldy(不便的).
To accommodate large projects, ASP.NET MVC lets you partition Web applications into smaller units that are referred to as areas. Areas provide a way to separate a large MVC Web application into smaller functional groupings. An area is effectively an MVC structure inside an application. An application could contain several MVC structures (areas).
For example, a single large e-commerce application might be divided into areas that represent the storefront, product reviews, user account administration, and the purchasing system. Each area represents a separate function of the overall application.
This walkthrough demonstrates how to implement areas in an ASP.NET MVC application. The walkthrough creates the functional framework for a blog site that has the following areas:
  • Main. This is entry point to the Web application. This area includes the landing page and a log-in feature.
  • Blog. This area is used to display blog posts and to search the archive.
  • Dashboard. This area is used to create and edit blog posts.
To keep this tutorial simple, the areas do not contain logic to perform the actual tasks for the blog.
A Visual Studio project with source code is available to accompany this topic: Download.(MVC2的範例)

In order to complete this walkthrough, you will need:
  • Microsoft Visual Studio 2008 Service Pack 1 or Visual Web Developer 2008 Express Edition Service Pack 1, or a later version.
  • The ASP.NET MVC 2 framework. If you have installed Visual Studio 2010, the ASP.NET MVC 2 is already installed on your computer. To download the most up-to-date version of the framework, see the ASP.NET MVC download page.
This walkthrough assumes that you are familiar with ASP.NET MVC. For more information, see ASP.NET MVC 2(MSDN的MVC2).

To begin, you will create an ASP.NET MVC project and add the folder structure for two child areas (Blog and Dashboard).

To create the application structure

  1. In Visual Studio, in the File menu, and click New Project.
  2. In the Project types window, expand the Visual Basic node or the Visual C# node, and then select theWeb node.
  3. In the Templates window, select ASP.NET MVC 2 Web Application.
  4. Name the project MvcAreasApplication, set the project location, and then select the Create directory for solution check box.
  5. Click OK.
  6. In Solution Explorer, right-click the project name, click Add, and then click Area.
  7. In Area Name, type Blog and then click Add.
    An Areas folder is added to the project. The Areas folder contains a folder structure that allows each child area to have its own models, views, and controllers.
  8. In Solution Explorer, right-click the project name, click Add, and then click Area.
  9. In Area Name, enter Dashboard and then click Add.
    When you are done, the Areas folder contains two child areas, Blog and Dashboard.

You will now add area-enabled controllers and action methods for each area.

To add area controllers

  1. In Solution Explorer, right-click the Controllers subfolder for the Blog area, click Add, and then clickController.
  2. Name the controller BlogController and then click Add.
  3. Add the following code to the BlogController class.
    using System;  using System.Collections.Generic;  using System.Linq;  using System.Web;  using System.Web.Mvc;  using System.Web.Mvc.Ajax;    namespace MvcAreasApplication.Areas.Blog.Controllers  {      public class BlogController : Controller      {          public ActionResult ShowRecent()          {              return View();          }            public ActionResult ShowArchive()          {              return View();          }      }  }      
    This code creates two action methods named ShowRecent and ShowArchive. To keep this tutorial simple, the action methods do not contain logic to perform specific tasks.
  4. In the Dashboard area, right-click the Controllers subfolder, click Add, and then click Controller.
  5. Name the controller DashboardController and click Add.
  6. Add the following code to the DashboardController class.
    using System;  using System.Collections.Generic;  using System.Linq;  using System.Web;  using System.Web.Mvc;  using System.Web.Mvc.Ajax;    namespace MvcAreasApplication.Areas.Dashboard.Controllers  {      public class DashboardController : Controller      {          public ActionResult AddPost()          {              return View();          }            public ActionResult EditPost()          {              return View();          }      }  }      
    This code creates two action methods named AddPost and EditPost. To keep this tutorial simple, the action methods do not contain logic to perform specific tasks.

Next you will add area-enabled views for each action method.

To add area views

  1. Open the BlogController class, right-click inside the ShowRecent action method, click Add View, and then click Add.
  2. In the ShowRecent view, add the following markup to the page content after the header:
    <p><%= Html.ActionLink("Show Archive", "ShowArchive") %></p>  
    This markup creates a link to the ShowArchive action method that you created earlier.
  3. Right-click inside the ShowArchive method, click Add View, and then click Add.
  4. In the ShowArchive view, add the following markup to the page content after the header:
    <p><%= Html.ActionLink("Show Recent", "ShowRecent") %></p>  
  5. Open the DashboardController class, right-click inside the AddPost action method, click Add View, and then click Add.
  6. In the AddPost view, add the following markup to the page content after the header:
    <p><%= Html.ActionLink("Edit Post", "EditPost") %></p>  
  7. Right-click inside the EditPost method, click Add View, and then click Add.
  8. In the EditPost view, add the following markup to the page content after the header:
    <p><%= Html.ActionLink("Add Post", "AddPost") %></p>  

When you add an area to a project, a route for the area is defined in an AreaRegistration file. The route sends requests to the area based on the request URL. To register routes for areas, you add code to the Global.asax file that can automatically find the area routes in the AreaRegistration file.

To register area routes

  1. In Solution Explorer, open the Global.asax file for the project.
  2. Insert the following code into the Application_Start method:
      AreaRegistration.RegisterAllAreas();  
      AreaRegistration.RegisterAllAreas()  
    This code calls the route registration methods for each child area.

In an ASP.NET MVC area application, you can link within an area as you would in any MVC application. For example, you can call the ActionLink method, or you can call any other routine that takes a controller or action name (such as the RedirectToAction method).
However, to generate a link to a different area, you must explicitly pass the target area name in the routeValuesparameter for these methods. For example, the following markup shows a link to the ShowBlog action method ofBlogController class. This call does not identify a specific area.
<%= Html.ActionLink("Show Blog", "ShowBlog", "Blog") %>
The link will work as expected anywhere within the Blog area. However, if the preceding link is added to a view in the Dashboard area, it will fail. This is because the ASP.NET MVC framework would not be able to find theBlogController class in the Dashboard area.
The following example shows how to create a link that identifies the area in an anonymous object passed in therouteValues parameter. This example is shown only as an explanation. Do not add it to your project.
<%= Html.ActionLink("Show Blog", "ShowBlog", "Blog", new { area = "blog" }, null) %>  
NoteNote
The last null parameter (Nothing in Visual Basic) is required only because the ActionLink method overloads that have a routeValues parameter also have an htmlAttributes parameter. However, this parameter is not required in order to be able to link between areas.

Adding Content to the Main Project

When you created the Visual Studio solution for this walkthrough, the solution template included a master view that acts as the entry point for the application. In this section of the walkthrough, you will add tabs to the master view that link to the child areas. You will also add code to display diagnostic information, including the name of the controller, action method, and area that produced the current view.

To add content to the main project

  1. Open the master view (Views\Shared\Site.Master).
  2. Insert the following code directly after the <asp:ContentPlaceHolder ID="MainContent" runat="server" /> element.
    <p>      Controller: <%= ViewContext.RouteData.Values["controller"] %><br />      Action: <%= ViewContext.RouteData.Values["action"] %><br />      Area: <%= ViewContext.RouteData.DataTokens["area"] %>  </p>      
    This code adds diagnostic information to the views.
  3. In the same file, find the <ul id="menu"> element and replace the whole element with the following code:
    <ul id="menu">                    <li><%= Html.ActionLink("Home", "Index", "Home", new { area = "" }, null)%></li>      <li><%= Html.ActionLink("Blog", "ShowRecent", "Blog", new { area = "blog" }, null)%></li>      <li><%= Html.ActionLink("Dashboard", "AddPost", "Dashboard", new { area = "dashboard" }, null)%></li>      <li><%= Html.ActionLink("About", "About", "Home", new { area = "" }, null)%></li>  </ul>      
    This code adds tabs that link across areas.

Now you can build and test the application.

To build and run the application

  1. Click CTRL-F5 to build the solution and run the application.
    The default MVC template home page is displayed in the browser. The page shows the current controller (Home), the action that generated the page (Index), and the current area, which is blank and which indicates the main area.
  2. Click the Blog tab.
    The ShowBlog page is displayed. The ShowBlog page contains a link to the ShowArchive page. The current controller is changed to Blog. The action is ShowBlog, and the area is blog.
  3. Click Show Archive.
    Notice that the controller and area remain the same, but the action is now ShowArchive.
  4. Click the Dashboard tab.
    The AddPost page is displayed. The AddPost page contains a link to the EditPost page. The controller is now Dashboard, the action is AddPost, and the area is dashboard.
  5. Continue navigating the Web site and notice the changes to the controller, action, and area.

Other Resources


2013年8月9日 星期五

VM RHEL 5 安裝 yum 的過程

因為RHEL 5新安裝後, 出現
This system is not registered with RHN.
RHN support will be disabled.

第一步請先檢查你的RedHat的DNS解析是否有問題!! 如果不行再繼續往下.

沒有去處理官方的要求, 如果你有原版序號, 大概沒有這個問題, 因為這台沒有, 所以直接換成centos的yum組件.


0先檢查 /etc/yum.repos.d/rhel-debuginfo.repo 這個檔案,

原來的內容是:
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/$basearch/Debuginfo/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

我有把repo檔的內容載下來, 新的repo內容在最下面

注意,如果你的yum 可以 更新, eg: #yum update 可以執行, 下面的步驟就不用執行了


 1.卸载redhat的yum组件

# rpm -qa | grep yum | xargs rpm -e --nodeps

2.下載yum*.rpm 

到 rpm.pbone.net 這個網頁
eg:

(建了一個臨時的/usr/scource 下載需要的 rpm )
wget ftp://ftp.univie.ac.at/systems/linux/dag/redhat/el5/en/ppc/fabian/RPMS/yum-2.4.2-0.4.el5.rf.noarch.rpm

3.  安裝rpm

rpm -ivh yum-2.4.2-0.4.el5.rf.noarch.rpm
yum就正常可以使用了(版本2.4.2)

4.  更新yum

#yum install yum
更新到最新版

PS:補充 rhel-debuginfo.repo的內容 (來源 http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo )
rhel-debuginfo.repo