25 tháng 12, 2014
19 tháng 11, 2014
10 tháng 11, 2014
Cài lại Postgres phiên bản cao hơn
Sau khi máy bạn đã cài Postgres thì nếu bạn muốn xóa cài đặt để cài lại postgres với phiện bản mới hơn bạn phải làm động tác này trước khi muốn cài mới.
Run Administrator CMD sau đó gõ lệnh : net user /delete postgres sau đó Enter
Để xóa đi services account
Chúc bạn thành công.
Run Administrator CMD sau đó gõ lệnh : net user /delete postgres sau đó Enter
Để xóa đi services account
Chúc bạn thành công.
10 tháng 10, 2014
HƯỚNG DẪN SỬ DỤNG CÔNG CỤ INTELLIJ BUILD VÀ DEBUG MAVEN PROJECT
1. Tải và cài đặt Intellij
-
Crack tìm trên mạng
2. Import maven project có sẵn
-
Khởi động Intellij lên bạn sẽ thấy rất nhiều tùy
chọn như Create New, Import,… Bạn chọn import à
chọn tới file pom.xml của project à Next cho đến khi kết
thúc.
3. Tạo lệnh build all (tất cả project)
-
Vào menu Run
à Edit Configurations à Click vào dấu + màu xanh chọn
Maven, đặt tên(Name), trỏ tới thư mục
project tổng(Working directory), viết lệnh clean
install ngay dòng Command line à Apply à OK. Nhấn Ctrl + Space nếu quên câu lệnh
4. Tạo lệnh build web
-
Vào menu Run
à Edit Configurations à Click vào dấu + màu xanh chọn
Maven, đặt tên(Name), trỏ tới thư mục
project tổng(Working directory), viết lệnh clean
install package liferay:deploy ngay dòng Command line à Apply à OK. Nhấn Ctrl + Space nếu quên câu lệnh
5. Cấu hình tomcat chạy trong chính
Intellij
-
Vào menu Run
à Edit Configurations à Click vào dấu + màu xanh chọn
Tomcat Server à Local. Ngay tại tab Server
chổ Application server bạn trỏ tới
thư mục server tomcat của mình.
6. Cấu hình debug
-
Sau khi tạo Server Tomcat xong ở bước 5. Bạn chọn
qua thẻ StartUp/Connection.
-
Trỏ chuột tới chổ Run à
xuống chổ Environment Variables.
o
Chọn dấu + tại ô Name gõ vào CATALINA_BASE.
o
Chọn dấu + tại ô Name gõ vào JRE_HOME.
-
Trỏ chuột tới chổ Debug à
xuống chổ Environment Variables.
o
Chọn dấu + tại ô Name gõ vào CATALINA_BASE.
o
Chọn dấu + tại ô Name gõ vào JRE_HOME.
o
Có thêm dòng JAVA_OPTS.
-
Phần Before
Lauch xóa trống hết.
7. Cấu hình Maven home directory
-
Download apache-maven về máy.
Vào menu File
à Settings
à Chọn Maven,
ngay chổ Maven home directory
chúng ta trỏ tới ngay thư mục chứ
apache-maven.
26 tháng 9, 2014
Cách vào thư mục webapps trong server tomcat
Để upload file lên thư mục webapss khi dùng primefaces JSF bạn cần phải xác định thư mục hiện tại(BIN)
public static String workingDir = System.getProperty("user.dir"); // 1 so truong hop bị lỗi khi lên server linus
Cập nhật:
File catalinaBase = new File(System.getProperty("catalina.base")).getAbsoluteFile();
public String workingDir = catalinaBase.getPath();
Ra ngoài thư mục BIN
public static String parentDir = workingDir.substring(0,
workingDir.lastIndexOf(File.separator));// ra ngoai thu muc BIN
Trỏ vào thư mục webapps của server
public static String webappsDir = parentDir + File.separator + "webapps";
Tiến hành upload file vào thư mục này.
Hàm tạo thư mục
public static void createDirectoryIfNeeded(String directoryName)
{
File theDir = new File(directoryName);
// if the directory does not exist, create it
if (!theDir.exists()) {
System.out.println("creating directory: " + directoryName);
theDir.mkdir();
}
}
Như vậy các file upload của bạn sẽ không bị xóa khi restart lại tomcat hay khi build lại source.
Thanks
public static String workingDir = System.getProperty("user.dir"); // 1 so truong hop bị lỗi khi lên server linus
Cập nhật:
File catalinaBase = new File(System.getProperty("catalina.base")).getAbsoluteFile();
public String workingDir = catalinaBase.getPath();
Ra ngoài thư mục BIN
public static String parentDir = workingDir.substring(0,
workingDir.lastIndexOf(File.separator));// ra ngoai thu muc BIN
Trỏ vào thư mục webapps của server
public static String webappsDir = parentDir + File.separator + "webapps";
Tiến hành upload file vào thư mục này.
Hàm tạo thư mục
public static void createDirectoryIfNeeded(String directoryName)
{
File theDir = new File(directoryName);
// if the directory does not exist, create it
if (!theDir.exists()) {
System.out.println("creating directory: " + directoryName);
theDir.mkdir();
}
}
Như vậy các file upload của bạn sẽ không bị xóa khi restart lại tomcat hay khi build lại source.
Thanks
10 tháng 7, 2014
Jquery Loader
Tạo hiệu ứng progress khi tải trang với JqueryLoader. Chỉ cần include 2 file này (Sau khi giải nén mới có) thì trang web của bạn sẽ có hiệu ứng.
Source download:
http://www.mediafire.com/download/9cxlsrj0vlm5zzd/JqueryLoader.7z
Source download:
http://www.mediafire.com/download/9cxlsrj0vlm5zzd/JqueryLoader.7z
30 tháng 5, 2014
Webstorm Key
| username: webstorm |
| key |
| ===== LICENSE BEGIN ===== |
| 72149-12042010 |
| 00000cI5EYta7xt""jWOIDohDqQx7S |
| SSsCH4oSb"1Y4edvtuSYyQ"iqGYhuo |
| !8r1Zrqkj"TmWPZ!Eu"puCi6KV2SVe |
| ===== LICENSE END ===== |
22 tháng 5, 2014
Java bỏ dấu chuổi tiếng việt
public static final String SPECIAL_CHARACTERS_TEMP = "àÀảẢãÃáÁạẠăĂằẰẳẲẵẴắẮặẶâÂầẦẩẨẫẪấẤậẬđĐèÈẻẺẽẼéÉẹẸêÊềỀểỂễỄếẾệỆìÌỉỈĩĨíÍịỊòÒỏỎõÕóÓọỌôÔồỒổỔỗỖốỐộỘơƠờỜởỞỡỠớỚợỢùÙủỦũŨúÚụỤưƯừỪửỬữỮứỨựỰýÝ :+\\<>\"*,!?%$=@#~[]`|^";
public static final String REPLACEMENTS_TEMP = "aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAdDeEeEeEeEeEeEeEeEeEeEeEiIiIiIiIiIoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOuUuUuUuUuUuUuUuUuUuUuUyY-___\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
public static char[] SPECIAL_CHARACTERS = SPECIAL_CHARACTERS_TEMP
.toCharArray();
public static char[] REPLACEMENTS = REPLACEMENTS_TEMP.toCharArray();
public static String toUrlFriendly(String s) {
int maxLength = Math.min(s.length(), 236);
char[] buffer = new char[maxLength];
int n = 0;
for (int i = 0; i < maxLength; i++) {
char ch = s.charAt(i);
buffer[n] = removeAccent(ch);
// skip not printable characters
if (buffer[n] > 31) {
n++;
}
}
// skip trailing slashes
while (n > 0 && buffer[n - 1] == '/') {
n--;
}
return String.valueOf(buffer, 0, n);
}
public static char removeAccent(char ch) {
int index = SPECIAL_CHARACTERS_TEMP.indexOf(ch);
if (index >= 0) {
ch = REPLACEMENTS[index];
}
return ch;
}
public static String removeAccent(String s) {
StringBuilder sb = new StringBuilder(s);
for (int i = 0; i < sb.length(); i++) {
sb.setCharAt(i, removeAccent(sb.charAt(i)));
}
return sb.toString();
}
public static final String REPLACEMENTS_TEMP = "aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAdDeEeEeEeEeEeEeEeEeEeEeEiIiIiIiIiIoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOuUuUuUuUuUuUuUuUuUuUuUyY-___\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
public static char[] SPECIAL_CHARACTERS = SPECIAL_CHARACTERS_TEMP
.toCharArray();
public static char[] REPLACEMENTS = REPLACEMENTS_TEMP.toCharArray();
public static String toUrlFriendly(String s) {
int maxLength = Math.min(s.length(), 236);
char[] buffer = new char[maxLength];
int n = 0;
for (int i = 0; i < maxLength; i++) {
char ch = s.charAt(i);
buffer[n] = removeAccent(ch);
// skip not printable characters
if (buffer[n] > 31) {
n++;
}
}
// skip trailing slashes
while (n > 0 && buffer[n - 1] == '/') {
n--;
}
return String.valueOf(buffer, 0, n);
}
public static char removeAccent(char ch) {
int index = SPECIAL_CHARACTERS_TEMP.indexOf(ch);
if (index >= 0) {
ch = REPLACEMENTS[index];
}
return ch;
}
public static String removeAccent(String s) {
StringBuilder sb = new StringBuilder(s);
for (int i = 0; i < sb.length(); i++) {
sb.setCharAt(i, removeAccent(sb.charAt(i)));
}
return sb.toString();
}
28 tháng 4, 2014
Trang tải các cài đặt mã nguồn mở
Việc cấu hình bằng tay cho source mã nguồn mở thường phức tạp và gặp lỗi. Bạn chỉ cần truy cập vào trang này và down về và cài đặt thông thường như các ứng dụng khác.
https://bitnami.com/stacks
Have a nice day !
https://bitnami.com/stacks
Have a nice day !
15 tháng 4, 2014
Cách tạo mục lục tự động trong word 2007 hoặc 2010
Chọn qua thẻ References và thao tác.
Lưu ý chổ "Add Text", "Table of Contents", "Update Table".
- Add Text: chứa các cấp độ (Level1, Level 2,..) của mục lục, mặc định sẽ có 3 Level.
+ Để add thêm level vào chổ "Add Text": References > Table of Contents > Insert Table of Contents, tìm đến chổ Show levels: mặc định là 3, bạn có thể chọn lên 4,5,6,...
- Đưa các tiêu đề vào tương ứng các level của nó bằng cách bôi đen tiêu đề đó và chọn Add Text vào Level tương ứng:
+ Ví dụ Add Text với cấp độ đầu tiên Level 1
Lưu ý: các định dạng có thể bị thay đổi sau khi Add Text, mình sẽ hướng dẫn cách chỉnh lại sau. tiếp tục...
+ Ví dụ Add Text với cấp độ thứ 2 Level 2.
- Kết quả sau khi chọn sẽ là :
(Cái này mình làm demo nên số trang là 1 hết, đừng lo nhé nếu bài của bạn có nội dung số trang sẽ đúng như trong bài của bạn thôi)
- Trường hợp nếu bạn Add Text nhầm cấp độ hoặc Add thiếu hoặc bạn thêm nôi dung nên mục lục bị thay đổi thì bạn cứ bôi đen các tiêu đề chưa đươc Add đó, rồi Add Text vào. Bây giờ bạn không cần vào chổ Table of Content để chọn Automatic Table 1 hay Automatic Table 2 nữa mà bạn chỉ cần click vào Update Table (nằm gần Table of Contents)
Lưu ý chổ "Add Text", "Table of Contents", "Update Table".
- Add Text: chứa các cấp độ (Level1, Level 2,..) của mục lục, mặc định sẽ có 3 Level.
+ Để add thêm level vào chổ "Add Text": References > Table of Contents > Insert Table of Contents, tìm đến chổ Show levels: mặc định là 3, bạn có thể chọn lên 4,5,6,...
- Đưa các tiêu đề vào tương ứng các level của nó bằng cách bôi đen tiêu đề đó và chọn Add Text vào Level tương ứng:
+ Ví dụ Add Text với cấp độ đầu tiên Level 1
+ Ví dụ Add Text với cấp độ thứ 2 Level 2.
- Cứ tương tự như thế Add Text tất cả các tiêu đề mình cần làm mục lục.
- Sau khi add xong tất cả (Nếu thiếu có thể Add sau) ta đưa con trỏ chuột tới chổ ta cần xuất ra mục lục chọn vào "Table of Contents" bạn có thể chọn "Automatic Table 1" hoặc "Automatic Table 2".

(Cái này mình làm demo nên số trang là 1 hết, đừng lo nhé nếu bài của bạn có nội dung số trang sẽ đúng như trong bài của bạn thôi)
- Trường hợp nếu bạn Add Text nhầm cấp độ hoặc Add thiếu hoặc bạn thêm nôi dung nên mục lục bị thay đổi thì bạn cứ bôi đen các tiêu đề chưa đươc Add đó, rồi Add Text vào. Bây giờ bạn không cần vào chổ Table of Content để chọn Automatic Table 1 hay Automatic Table 2 nữa mà bạn chỉ cần click vào Update Table (nằm gần Table of Contents)
- Một hộp thoại hiện ra:
+ Nếu bạn chọn: Update page numbers only thì mục lục của bạn sẽ chỉ cập nhật lại số trang thôi.
+ Nếu bạn chọn: Update entire table thì mục lục sẽ cập nhật lại nôi dung cũng như số trang (Nên chọn cái này).
- Chúc các bạn thành công (^_^). Office 2010
11 tháng 4, 2014
Liferay: How to move default portlet to another section in control panel
Hi all,
This is the code to include your-portlet into control panel in liferay:
"- control-panel-entry-category default has 4 section : my, content, portal, server"
You can insert code above into liferay-portlet.xml.
If the default portlet for example (User Admin,...) then Where liferay-portlet.xml ? This post will help you.
Now, Go to Server (Tomcat) - webapps - ROOT - WEB-INF, You will see liferay-portlet.xml and Here contain all default portlet you want.
Final you only insert code above into what liferay-portlet you want.
Thank you.
This is the code to include your-portlet into control panel in liferay:
"- control-panel-entry-category default has 4 section : my, content, portal, server"
You can insert code above into liferay-portlet.xml.
If the default portlet for example (User Admin,...) then Where liferay-portlet.xml ? This post will help you.
Now, Go to Server (Tomcat) - webapps - ROOT - WEB-INF, You will see liferay-portlet.xml and Here contain all default portlet you want.
Final you only insert code above into what liferay-portlet you want.
Thank you.
11 tháng 12, 2013
Javascript Validator problem in Eclipse
Right click vào Project chọn Properties chọn xuống chổ Builders sau đó bỏ check chọn chổ JavaScript Validator
7 tháng 12, 2013
Đánh số trang (PageNumber) từ 1 trang bất kỳ.
Ví dụ ở đây bạn muốn đánh trang số 1 bắt đầu từ trang thứ 3
thì làm như sau:
- Đưa con trỏ chuột vào
trang thứ 2, Chọn qua thẻ Page Layout, Chọn Breaks, Chọn Next Page

- Click vào trang thứ 3, Chọn quan thẻ Insert, Chọn Page Number, Chọn Format Page Number

Một hộp thoại hiện ra như sau :
Nhớ chọn giống như hình trên : Start at: 1.
- Chọn nơi để chèn số trang:
Trên (Top of page), Dưới (Bottom of
page),.., Ví dụ mình chọn chính giữa bên dưới
Khi đó số trang sẽ được đánh như sau:
|
Trang thứ 1
|
Đánh số 1
|
|
Trang thứ 2
|
Đánh số 2
|
|
Trang thứ 3
|
Đánh số 1
|
|
Trang thứ 4
|
Đánh số 2
|
|
Trang thứ 5
|
Đánh số 3
|
- Double click vào số 1 ở
trang thứ 3. Click vào nút

để bỏ kết nối giữa các session sau khi mình break (Next Page). - Double click vào số 1 ở
trang thứ nhất xóa số trang này đi thì nó sẽ tự xóa tất cả số trang ở session thứ nhất (Session thứ nhất này mình gồm 2 trang đầu tiên) là xong.
28 tháng 11, 2013
Tomcat không kết nối được mysql
Mô tả lỗi:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have a
n error in your SQL syntax; check the manual that corresponds to your MySQL serv
er version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=DEFAULT' at
line 1
Cách khắc phục:
Cách khắc phục:
- Download Mysql Connector sau đó giải nén thành file .jar bỏ vào thư mục tomcat/lib/ext của tomcat.
- Khởi động lại server tomcat là OK
23 tháng 11, 2013
Mysql port xung đột khi cài Mysql Workbench với Mysql Xampp hoặc Wamp
Khi bạn cài MYSQL WORKBENCH vào cùng với XAMPP hoặc WAMP sẽ xãy ra tình trạng đụng port cơ sở dữ liệu 3306. Vì vậy để khắc phục lỗi này ta tắt 1 trong những dịch vụ.
Sau đây là cách tắt service của MYSQL WORKBENCH để chạy MYSQL XAMPP.
Sau đây là cách tắt service của MYSQL WORKBENCH để chạy MYSQL XAMPP.
- Nhấn tổ hợp phím "Lá cờ (gần nút Alt) + R", sau đó gõ services.msc.
- Tìm tới MySQL56, click chuột phải lên chọn Stop.
- Khởi động lại Mysql Xampp.
7 tháng 11, 2013
HƯỚNG DẪN KẾT HỢP JASPER REPORT VỚI DYNAMIC JASPER
1. Thiết
kế phần tỉnh của báo cáo
Chúng
ta có thể dùng Ireport để design những phần thông tin tỉnh như header hay footer, sau khi design xong ta lưu
lại file với tên là file*.jrxml.
2.
Generate
phần dữ liệu động lên mẫu tỉnh đã design
Tạo
DynamicReport
DynamicReportBuilder drb = new DynamicReportBuilder();
Tạo
các column động
ColumnBuilder columnName = ColumnBuilder.getNew();
columnName.setTitle("Name");
columnName.setWidth(180);
columnName.setFixedWidth(true);
columnName.setColumnProperty("name",
String.class.getName());
columnName.setHeaderStyle(headerStyle);
ColumnBuilder columnYear = ColumnBuilder.getNew();
columnYear.setTitle("Year");
columnYear.setWidth(180);
columnYear.setFixedWidth(true);
columnYear.setColumnProperty("year",
Integer.class.getName());
columnYear.setHeaderStyle(headerStyle);
columnYear.setStyle(rightStyle);
DynamicReport dr = drb.addColumn(columnName.build())
.addColumn(columnYear.build()) .setPrintBackgroundOnOddRows(true).setUseFullPageWidth(true)
.build();
for (int i = 1; i < 3; i++) {
ColumnBuilder
columnBuilder= ColumnBuilder.getNew();
columnBuilder.setTitle("Column
Add");
columnBuilder.setColumnProperty("year"+i,Integer.class.getName());
columnBuilder.setWidth(100);
columnBuilder.setFixedWidth(true);
drb.addColumn(columnBuilder.build());
}
Đọc
file mẫu mình đã thiết kế các phần tỉnh
drb.setTemplateFile("E:\\Phien\\TemplateReports\\file*.jrxml");
Xuất ra file excel , word, pdf
JRDataSource ds = new JRBeanCollectionDataSource(listData);
JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr,new
ClassicLayoutManager(), ds);
JasperViewer.viewReport(jp); // finally display the report
report
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"d://design_jasper_sample_report1.xls");
exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE,
true);
exporter.exportReport();
Lưu ý: Phải add thư viện
DynamicJasper-5.0.0.jar với jasperreports-5.5.0 vào project
3 tháng 11, 2013
Upload, Download in Liferay JSF
- File resource_handler
public class App3ResourceHandler extends ResourceHandlerWrapper {public static final String LIBRARY_NAME_BCTHSD = "THSD";
public static final String FileDownload = "Download";
// Logger
private static final Logger logger = LoggerFactory
.getLogger(App3ResourceHandler.class);
// Private Data Members
private ResourceHandler wrappedResourceHandler;
public App3ResourceHandler(ResourceHandler wrappedResourceHandler) {
this.wrappedResourceHandler = wrappedResourceHandler;
}
@Override
public Resource createResource(String resourceName, String libraryName) {
if (libraryName.equals(LIBRARY_NAME_BCD)) {
if (BaoCaoDongExel.RESOURCE_NAME.equals(resourceName)) {
try {
BaoCaoDongBean baocaoSLTSTGBHBean = (BaoCaoDongBean) FacesContext
.getCurrentInstance().getExternalContext()
.getSessionMap().get("baocaodongbean");
Resource re = baocaoSLTSTGBHBean.getExport();
return re;
} catch (Exception e) { //
// TODO: handle exception return
wrappedResourceHandler.createResource(resourceName,
libraryName);
}
} else {
return wrappedResourceHandler.createResource(resourceName,
libraryName);
}
} else if (libraryName.equals(LIBRARY_NAME_BCTHSD)) {
if (BCTHSD_Export_Resource.RESOURCE_NAME.equals(resourceName)) {
try {
BaoCaoTinhHinhSuDungBean baocaoTHSDBean = (BaoCaoTinhHinhSuDungBean) FacesContext
.getCurrentInstance().getExternalContext()
.getSessionMap().get("baoCaoTinhHinhSuDungBean");
Resource re = baocaoTHSDBean.getExport();
return re;
} catch (Exception e) { //
// TODO: handle exception return
wrappedResourceHandler.createResource(resourceName,
libraryName);
}
} else {
return wrappedResourceHandler.createResource(resourceName,
libraryName);
}
}
return wrappedResourceHandler.createResource(resourceName, libraryName);
}
@Override
public void handleResourceRequest(FacesContext facesContext)
throws IOException {
ExternalContext externalContext = facesContext.getExternalContext();
String libraryName = externalContext.getRequestParameterMap().get("ln");
String resourceName = externalContext.getRequestParameterMap().get(
"javax.faces.resource");
String folderName = externalContext.getRequestParameterMap().get("BC1");
Resource resource = createResource(resourceName, libraryName);
ReadableByteChannel readableByteChannel = null;
WritableByteChannel writableByteChannel = null;
InputStream inputStream = null;
int bufferSize = 1024;
ByteBuffer byteBuffer = ByteBuffer.allocate(bufferSize);
try {
// Open an input stream in order to read the resource's
// contents/data.
if (libraryName.equalsIgnoreCase(FileDownload)) {
String path = FacesContext.getCurrentInstance()
.getExternalContext().getRealPath("");
if (folderName.equalsIgnoreCase("none")) {
path = path + File.separator + resourceName;
} else {
path = path + File.separator + folderName + File.separator
+ resourceName;
}
try {
File file = new File(path);
inputStream = new FileInputStream(file);
} catch (IOException e) {
// TODO: handle exception
System.out
.println("Rat tiec toi khong tim thay file ban can!");
}
} else {
inputStream = resource.getInputStream();
}
if (inputStream != null) {
// Set the response buffer size.
int responseBufferSize = byteBuffer.capacity();
externalContext.setResponseBufferSize(responseBufferSize);
String responseContentType = resource.getContentType();
externalContext.addResponseHeader("Content-Disposition",
"attachment; filename=" + resourceName);
if (responseContentType != null) {
externalContext.setResponseContentType(responseContentType);
}
// Copy the bytes in the resource's input stream to the
// response's output stream.
int responseContentLength = 0;
readableByteChannel = Channels.newChannel(inputStream);
writableByteChannel = Channels.newChannel(externalContext
.getResponseOutputStream());
int bytesRead = readableByteChannel.read(byteBuffer);
int bytesWritten = 0;
while (bytesRead != -1) {
byteBuffer.rewind();
byteBuffer.limit(bytesRead);
do {
bytesWritten += writableByteChannel.write(byteBuffer);
} while (bytesWritten < responseContentLength);
byteBuffer.clear();
responseContentLength += bytesRead;
bytesRead = readableByteChannel.read(byteBuffer);
if (logger.isTraceEnabled()) {
// Surround with isTraceEnabled check in order to avoid
// unnecessary conversion
// of int to String.
logger.trace("Handling - MORE bytesRead=[{0}]",
Integer.toString(bytesRead));
}
}
// Now that we know how big the file is, set the response
// content length.
externalContext.setResponseContentLength(responseContentLength);
externalContext.setResponseStatus(HttpServletResponse.SC_OK);
logger.debug(
"HANDLED (SC_OK) resourceName=[{0}], libraryName[{1}], responseContentType=[{2}], responseContentLength=[{3}]",
new Object[] { resourceName, libraryName,
responseContentType, responseContentLength });
}
} catch (IOException e) {
externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
logger.error(
"NOT HANDLED (SC_NOT_FOUND) resourceName=[{0}], libraryName[{1}], errorMessage=[{2}]",
new Object[] { resourceName, libraryName, e.getMessage() },
e);
} finally {
if (writableByteChannel != null) {
writableByteChannel.close();
}
if (readableByteChannel != null) {
readableByteChannel.close();
}
if (inputStream != null) {
inputStream.close();
}
}
}
@Override
public boolean libraryExists(String libraryName) {
if (LIBRARY_NAME.equals(libraryName)) {
return true;
} else {
return super.libraryExists(libraryName);
}
}
@Override
public ResourceHandler getWrapped() {
return wrappedResourceHandler;
}
}
- File resource
public class BaoCaoDongExel extends Resource {
public static final String CONTENT_TYPE = "application/vnd.ms-excel";
public static final String RESOURCE_NAME = "BaoCao.xls";
private String requestPath;
public BaoCaoDongExel() {
setLibraryName(App3ResourceHandler.LIBRARY_NAME_BCD);
setResourceName(RESOURCE_NAME);
setContentType(CONTENT_TYPE);
if (!Validator.isNull(listData)) {
this.listData.clear();
}
}
@Override
public InputStream getInputStream() throws IOException {
byte[] excel = new byte[] {};
try {
// code tạo file xuất ra ở đây
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
wb.write(byteArrayOutputStream);
excel = byteArrayOutputStream.toByteArray();
} catch (Exception e2) {
System.out.println("co loi trong " + getClass().getName() + "\n"
+ e2);
}
return new ByteArrayInputStream(excel);
}
@Override
public String getRequestPath() {
if (requestPath == null) {
StringBuilder buf = new StringBuilder();
buf.append(ResourceHandler.RESOURCE_IDENTIFIER);
buf.append("/");
buf.append(getResourceName());
buf.append("?ln=");
buf.append(getLibraryName());
buf.append("&");
buf.append("BC1");// chua hieu
buf.append("=");
buf.append(Math.random());
requestPath = buf.toString();
}
return requestPath;
}
@Override
public Map getResponseHeaders() {
// TODO Auto-generated method stub
return null;
}
@Override
public URL getURL() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean userAgentNeedsUpdate(FacesContext arg0) {
// TODO Auto-generated method stub
return false;
}
}
- File bean
private BaoCaoDongExel export;
public BaoCaoDongExel getExport() {
export = new BaoCaoDongExel(các tham số truyền qua tương ứng);
return export;
}
public void setExport(BaoCaoDongExel export) {
this.export = export;
}
- Download Bean
@ManagedBean (name="downloadBean")
public class DownloadBean {
public String getLink(String folder, String fileName) {
String link1 = null;
if (link1 == null) {
StringBuilder buf = new StringBuilder();
buf.append(ResourceHandler.RESOURCE_IDENTIFIER);
buf.append("/");
buf.append(fileName);
buf.append("?ln=");
buf.append(App3ResourceHandler.FileDownload);
buf.append("&");
buf.append("BC1");
buf.append("=");
buf.append(folder);
link1 = buf.toString();
}
return link1;
}
}
- File view
- Nếu file đã có sẳn thì down theo đường dẫn nó.
style="display:#{tailieu.existFile=='TRUE'?'block':'none'}"
value="#{downloadBean.getLink(customUtils.GetFolderUpload(),tailieu.tenFileLuu)}">
1 tháng 11, 2013
Microsoft Office Content-Type
Ext
|
MIME Type
|
.doc
|
application/msword
|
.dot
|
application/msword
|
.docx
|
application/vnd.openxmlformats-officedocument.wordprocessingml.document
|
.dotx
|
application/vnd.openxmlformats-officedocument.wordprocessingml.template
|
.docm
|
application/vnd.ms-word.document.macroEnabled.12
|
.dotm
|
application/vnd.ms-word.template.macroEnabled.12
|
.xls
|
application/vnd.ms-excel
|
.xlt
|
application/vnd.ms-excel
|
.xla
|
application/vnd.ms-excel
|
.xlsx
|
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
.xltx
|
application/vnd.openxmlformats-officedocument.spreadsheetml.template
|
.xlsm
|
application/vnd.ms-excel.sheet.macroEnabled.12
|
.xltm
|
application/vnd.ms-excel.template.macroEnabled.12
|
.xlam
|
application/vnd.ms-excel.addin.macroEnabled.12
|
.xlsb
|
application/vnd.ms-excel.sheet.binary.macroEnabled.12
|
.ppt
|
application/vnd.ms-powerpoint
|
.pot
|
application/vnd.ms-powerpoint
|
.pps
|
application/vnd.ms-powerpoint
|
.ppa
|
application/vnd.ms-powerpoint
|
.pptx
|
application/vnd.openxmlformats-officedocument.presentationml.presentation
|
.potx
|
application/vnd.openxmlformats-officedocument.presentationml.template
|
.ppsx
|
application/vnd.openxmlformats-officedocument.presentationml.slideshow
|
.ppam
|
application/vnd.ms-powerpoint.addin.macroEnabled.12
|
.pptm
|
application/vnd.ms-powerpoint.presentation.macroEnabled.12
|
.potm
|
application/vnd.ms-powerpoint.template.macroEnabled.12
|
.ppsm
|
application/vnd.ms-powerpoint.slideshow.macroEnabled.12
|
Đăng ký:
Bài đăng (Atom)







