j2ee学习
比我webwork还要简单
一、导入struts2-spring-plugin-2.0.11.1.jar
二、在web.xml加入:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
具体参考
http://www.99inf.net/SoftwareDev/Java/55131.htm
一、导入struts2-spring-plugin-2.0.11.1.jar
二、在web.xml加入:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
具体参考
http://www.99inf.net/SoftwareDev/Java/55131.htm
lunzi
2008-04-13 23:53:18
阅读:210
评论:0
引用:0
package org.lunzi.test.dao.test;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
public class BaseDaoTestCase extends AbstractDependencyInjectionSpringContextTests {
@Override
protected String[] getConfigLocations() {
return new String[] {"classpath:applicationContext.xml"};
}
}
lunzi
2008-04-13 23:49:55
阅读:212
评论:0
引用:0
对于null,或者miss value,freemarker会报错
!:default value operator,语法结构为:unsafe_expr!default_expr,比如 ${mouse!"No mouse."} 当mouse不存在时,返回default value;
(product.color)!"red" 这种方式,能够处理product或者color为miss value的情况;
而product.color!"red"将只处理color为miss value的情况
??: Missing value test operator ,测试是否为missing value
unsafe_expr?? :product.color??将只测试color是否为null
(unsafe_expr)??:(product.color)??将测试product和color是否存在null
?exists:旧版本的用法
比如:<#if mouse??>
Mouse found
<#else>
No mouse found
</#if>
Creating mouse...
<#assign mouse = "Jerry">
<#if mouse??>
Mouse found
<#else>
No mouse found
</#if>
转载地址:http://www.iocblog.net/static/2007/728.html
!:default value operator,语法结构为:unsafe_expr!default_expr,比如 ${mouse!"No mouse."} 当mouse不存在时,返回default value;
(product.color)!"red" 这种方式,能够处理product或者color为miss value的情况;
而product.color!"red"将只处理color为miss value的情况
??: Missing value test operator ,测试是否为missing value
unsafe_expr?? :product.color??将只测试color是否为null
(unsafe_expr)??:(product.color)??将测试product和color是否存在null
?exists:旧版本的用法
比如:<#if mouse??>
Mouse found
<#else>
No mouse found
</#if>
Creating mouse...
<#assign mouse = "Jerry">
<#if mouse??>
Mouse found
<#else>
No mouse found
</#if>
转载地址:http://www.iocblog.net/static/2007/728.html
lunzi
2008-03-20 14:49:13
阅读:1040
评论:0
引用:0
http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=29304&threadID=36772&messageID=238659
lunzi
2008-03-19 17:45:07
阅读:47
评论:0
引用:0
日期格式:${book.date?string('yyyy-MM-dd')}
lunzi
2008-02-26 17:20:20
阅读:513
评论:0
引用:0
第一、配置过滤器
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
第二、修改decorators.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<decorators defaultdir="/WEB-INF/decorator">
<!--¹ÜÀíÔ±ºǫ́-->
<decorator name="manage" page="managetest.jsp">
<pattern>/manage/*.action</pattern>
</decorator>
<decorator name="fore" page="fore.jsp">
<pattern>/fore/*.action</pattern>
</decorator>
<decorator name="test" page="test.jsp">
<pattern>/test/*.action</pattern>
</decorator>
</decorators>
第三、配置模板文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<%@ page contentType="text/html;charset=GBK" language="java" %>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<%@ taglib prefix="ww" uri="/webwork" %>
<%@ page language="java" contentType="text/html;charset=GBK" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>test</title>
<link href="/css/style.css" rel="stylesheet" type="text/css"/>
<decorator:head/>
</head>
<body>
<div id="area">
<div id="index_left"></div>
<div id="index_center">
<div id="top"><img src="/images/top.jpg" /></div>
<div id="dh"><a href="/index.html" target="_blank">首页</a> <a href="#">赛事介绍</a> <a href="#">在线充值</a> <a href="/newsList.html" target="_blank">赛事新闻</a> <a href="/videoList.html" target="_blank">图片报道</a> <a href="/videoInfo.html" target="_blank">精彩视频</a> <a href="/rules.html" target="_blank">比赛规则</a> <a href="/award.html" target="_blank">奖项设置</a> <a href="/agoRace.html" target="_blank">往界回顾</a></div>
<div id="dhx"></div>
<decorator:body/>
</div>
</div>
<div id="index_right"></div>
<!--</div>-->
<div id="footer">
test
</div>
</body>
</html>
lunzi
2008-02-20 10:28:30
阅读:316
评论:0
引用:0
1、DAO interface
package test.dao;
import java.util.List;
import test.model.Book;
public interface BookDAO {
void create(Book book);
List<Book> queryByAuthor(String author);
}
2、DAO Impl
package test.dao.impl;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import test.dao.BookDAO;
import test.model.Book;
public class BookDAOImpl extends JdbcDaoSupport implements BookDAO {
class BookRowMapper implements RowMapper {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
Book book = new Book();
book.setId(rs.getLong("id"));
book.setName(rs.getString("name"));
book.setAuthor(rs.getString("author"));
return book;
}
}
public void create(Book book) {
getJdbcTemplate().update(
"insert into book(id,name,author)values(book_seq.nextval,?,?)",
new Object[] { book.getName(), book.getAuthor() });
}
public List<Book> queryByAuthor(String author) {
return getJdbcTemplate().query("select * from book where author=?", new Object[]{author}, new BookRowMapper());
}
}
3、spring context
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!--========WebDb DataSource========================================================================-->
<!-- -->
<bean id="webdbDataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:lunzi"/>
<property name="username" value="webnews"/>
<property name="password" value="123456"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="webdbDataSource"/>
</bean>
<bean id="bookDao" class="test.dao.impl.BookDAOImpl">
<property name="dataSource" ref="webdbDataSource"/>
</bean>
</beans>
4、测试类
package test.dao.test;
import java.util.List;
import test.dao.BookDAO;
import test.model.Book;
public class BookDAOTest extends BaseDaoTestCase {
public BookDAO bookDao;
public void setBookDao(BookDAO bookDao){
this.bookDao = bookDao;
}
/*public void testCreateBook(){
Book book = new Book();
book.setAuthor("lunzi2");
book.setName("cow2");
this.bookDao.create(book);
}*/
public void testQueryByAuthor(){
List<Book> list = this.bookDao.queryByAuthor("lunzi2");
for(Book book:list){
System.out.println(book.getName());
}
super.assertNotNull(list);
}
}
lunzi
2008-02-17 15:32:56
阅读:617
评论:1
引用:0
1、action
package test.web.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import test.model.NewsModel;
import test.model.PageUtil;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionSupport;
public class HelloAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String hello;
private List<NewsModel> newsList = new ArrayList<NewsModel>();
private PageUtil pageUtil = new PageUtil();
public PageUtil getPageUtil() {
return pageUtil;
}
public void setPageUtil(PageUtil pageUtil) {
this.pageUtil = pageUtil;
}
public void setNewsList(List<NewsModel> newsList) {
this.newsList = newsList;
}
public List getNewsList() {
return newsList;
}
public String getHello() {
return hello;
}
public void setHello(String hello) {
this.hello = hello;
}
public String execute() throws Exception{
this.setHello("hello webwork!!!");
return SUCCESS;
}
@SuppressWarnings("unchecked")
public String getFirst() throws Exception{
newsList.add(new NewsModel(1,"newsTilte"));
newsList.add(new NewsModel(2,"newsTilte"));
pageUtil.setItems(newsList);
pageUtil.setPageSize(101);
Map request = (Map)ActionContext.getContext().get("request");
request.put("newsList",newsList);
request.put("pageUtil", pageUtil);
this.setHello("hello first!!!");
return SUCCESS;
}
}
2、jsp视图
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="ww" uri="/webwork" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>hello.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<ww:property value="hello"/><br/>
<ww:iterator value="#request['newsList']" id="book">
<ww:property value="#book.id"/>
<ww:property value="#book.title"/><br/>
</ww:iterator>
<ww:set name="page" value="#request.pageUtil"/>
<ww:iterator value="#page.items" id="news">
<ww:property value="#news.id"/>
<ww:property value="#news.title"/><br/>
</ww:iterator>
</body>
</html>
验证的一视图jsp代码
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="ww" uri="/webwork" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>hello.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form action="add.jhtml" method="post">
title:<input name="newsModel.title" value="<ww:property value="newsModel.title"/>">
<ww:if test="fieldErrors['newsModel.title']!=null">
<ww:property value="fieldErrors['newsModel.title']"/>
</ww:if><br>
<input type="submit" value="提交">
</form>
<ww:form method="post">
<ww:textfield label="Name" name="newsModel.title"/>
<ww:submit value="保存" />
</ww:form>
</body>
</html>
lunzi
2008-02-16 22:40:11
阅读:148
评论:0
引用:0
package test.action;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.thj.bookstore.model.InfoModel;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionSupport;
public class TestAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private String hello;
private int stepNum;
private InfoModel infoModel = new InfoModel();
private Map<Integer,InfoModel> stepMap = new HashMap<Integer,InfoModel>();
public InfoModel getInfoModel() {
return infoModel;
}
public void setInfoModel(InfoModel infoModel) {
this.infoModel = infoModel;
}
public int getStepNum() {
return stepNum;
}
public void setStepNum(int stepNum) {
this.stepNum = stepNum;
}
public String getHello() {
return hello;
}
public void setHello(String hello) {
this.hello = hello;
}
public int getTotalStep(){
if(ActionContext.getContext().getSession().get("stepNum")!=null){
return (Integer)ActionContext.getContext().getSession().get("stepNum");
}else{
return 0;
}
}
public String execute() throws Exception{
this.setHello("hello webwork!!");
return SUCCESS;
}
public String second() throws Exception{
Map session = ActionContext.getContext().getSession();
if(stepNum>0){
session.put("stepNum", stepNum);
}
stepNum = 1;
return SUCCESS;
}
public String next() throws Exception{
Map session = ActionContext.getContext().getSession();
//int totalStep = Integer.parseInt((String)session.get("stepNum"));
if(stepNum<=this.getTotalStep()){
if(stepNum==1){
stepMap.put(stepNum, infoModel);
session.put("part", stepMap);
}else{
stepMap = (Map)session.get("part");
if(!stepMap.containsKey(stepNum)){
System.out.println("next stepNum:"+stepNum);
stepMap.put(stepNum, infoModel);
session.put("part", stepMap);
}
}
if(stepNum==this.getTotalStep()){
stepMap = (Map)session.get("part");
for(Iterator it = stepMap.values().iterator();it.hasNext();){
infoModel = (InfoModel)it.next();
System.out.println("step:"+infoModel.getStep()+"\t");
System.out.println("name:"+infoModel.getName()+"\n");
}
session.remove("stepNum");
session.remove("part");
return NONE;
}
stepNum++;
}
return SUCCESS;
}
}
配置
<action name="hello" class="test.action.TestAction">
<result name="success">/hello.jsp</result>
</action>
<action name="second" class="test.action.TestAction" method="second">
<result name="success">/next.jsp</result>
</action>
<action name="next" class="test.action.TestAction" method="next">
<result name="success">/next.jsp</result>
</action>
hello.jsp
<%@ page contentType="text/html; charset=gb2312" %>
<%@ taglib prefix="ww" uri="/webwork"%>
<html>
<body>
<form action="second.action" method="post">
step:<input name="stepNum"/>
<input type="submit" value="提交"/>
</form>
<ww:property value="hello"/>
</body>
</html>
next.jsp
<%@ page contentType="text/html; charset=gb2312" %>
<%@ taglib prefix="ww" uri="/webwork"%>
<html>
<body>
<form action="next.action" method="post">
step:<input type="hidden" name="stepNum" value="<ww:property value="stepNum"/>"/>
<input name="infoModel.step" value="<ww:property value="stepNum"/>" readonly/>
<input name="infoModel.name" />
<input type="submit" value="提交"/>
</form>
</body>
</html>
lunzi
2008-01-09 00:26:12
阅读:99
评论:0
引用:0
<?xml version="1.0" encoding="GB2312"?>
<project name="ant test" default="main" basedir=".">
<target name="main">
<javac srcdir="src\main\hello\ant" destdir="build\classes"/>
<java classname="hello.ant.HelloAnt">
<classpath>
<pathelement path="build\classes"/>
</classpath>
</java>
</target>
</project>
<project name="ant test" default="main" basedir=".">
<target name="main">
<javac srcdir="src\main\hello\ant" destdir="build\classes"/>
<java classname="hello.ant.HelloAnt">
<classpath>
<pathelement path="build\classes"/>
</classpath>
</java>
</target>
</project>
lunzi
2007-12-16 21:38:24
阅读:76
评论:0
引用:0
