[size=xx-large]最终效果:[/size][color=red](注:第一幅图需要修改源码中的VM文件为以下代码)[/color]
[img]http://dl.iteye.com/upload/attachment/595447/0d215fb8-31c7-3e72-be70-ab61640dcce4.jpg[/img]
[img]http://dl.iteye.com/upload/attachment/595426/ba1fa811-93c7-3167-8b3c-2316423a8d0b.png[/img]
[size=large]Struts+Velocity整合示例,请访问:[/size]
[url]http://qiaolevip.iteye.com/blog/1276857[/url]
sql:
[size=xx-large]DBHelper:[/size]
VM
[img]http://dl.iteye.com/upload/attachment/595447/0d215fb8-31c7-3e72-be70-ab61640dcce4.jpg[/img]
[img]http://dl.iteye.com/upload/attachment/595426/ba1fa811-93c7-3167-8b3c-2316423a8d0b.png[/img]
[size=large]Struts+Velocity整合示例,请访问:[/size]
[url]http://qiaolevip.iteye.com/blog/1276857[/url]
sql:
CREATE TABLE `User` (
`id` int NOT NULL ,
`name` varchar(50) NULL
)
;
[size=xx-large]DBHelper:[/size]
package com.ape.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBHelper {
public static Connection getConn() {
Read read = new Read();
Connection conn = null;
try {
Class.forName(read.readProperties("driver")).newInstance();
conn = DriverManager.getConnection(read.readProperties("url"), read
.readProperties("username"), read
.readProperties("password"));
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public static void closeAll(Connection conn, PreparedStatement ps) {
try {
if (conn != null) {
conn.close();
}
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void closeAll(Connection conn, PreparedStatement ps,
ResultSet rs) {
try {
if (conn != null) {
conn.close();
}
if (ps != null) {
ps.close();
}
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
VM
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
li{
font-size: 20px;
color: green;
text-align: left;
}
lable{
color: red;
}
</style>
<li>$!name</li>
<table border="1">
<tr>
#foreach($user in $vector)
<td>
<li><lable>$velocityCount</lable>: $!user.id : $!user.name</li>
</td>
#if($velocityCount % 3 == 0)
</tr>
#end
#end
</table>
public String test() {
try {
vector = service.retrieve();
name = "Happy";
} catch (ResourceNotFoundException e) {
e.printStackTrace();
} catch (ParseErrorException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return "test";
}