论坛首页 Java版 Struts

ssh2整合

浏览 172 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
时间:2008-05-09
此项目增删改查基本要的都有了,集合了国际化,校验框架加上无法提交,还需要研究
Action类
package com.struts.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.hibernate.po.UserTab;
import com.hibernate.service.IUserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class UserAction extends ActionSupport {

	private IUserService dao;

	public IUserService getDao() {
		return dao;
	}

	public void setDao(IUserService dao) {
		this.dao = dao;
	}

	private UserTab user;

	public UserTab getUser() {
		return user;
	}

	public void setUser(UserTab user) {
		this.user = user;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		try {
			System.out.println("find");
			Map request = (Map) ActionContext.getContext().get("request");
			request.put("list", dao.findAll());
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public String save() throws Exception {
		try {
			dao.save(user);
			System.out.println("save");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public String see() throws Exception {
		try {
			user = dao.findById(user.getId());
			System.out.println("see");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public String delete() throws Exception {
		try {
			dao.delete(user);
			System.out.println("delete");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public String update() throws Exception {
		try {
			dao.update(user);
			System.out.println("update");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return SUCCESS;
	}

}


测试类
import java.util.Iterator;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hibernate.impl.UserService;
import com.hibernate.po.UserTab;

public class Test {

	public static void main(String[] args) {
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"applicationContext.xml");
		// UserTab user = new UserTab();
		UserService um = (UserService) ctx.getBean("userService");
		// user.setFirstname("张");
		// user.setLastname("三");
		// um.save(user);

		Iterator it = um.findAll().iterator();
		while (it.hasNext()) {
			UserTab u = (UserTab) it.next();
			System.out.println(u.getFirstname());
		}
	}
}

struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>

	<package name="user" extends="struts-default">

		<action name="find" class="userAction">
			<result>/list.jsp</result>
		</action>

		<action name="save" class="userAction" method="save">
			<interceptor-ref name="defaultStack" />
			<interceptor-ref name="token" />
			<result>/list.jsp</result>
			<result name="invalid.token">save.jsp</result>
			<result name="input">/save.jsp</result>
		</action>

		<action name="see" class="userAction" method="see">
			<result>/update.jsp</result>
			<result name="input">/update.jsp</result>
		</action>

		<action name="update" class="userAction" method="update">
			<result type="redirect">find.action</result>
			<result name="input">/index.jsp</result>
		</action>

		<action name="delete" class="userAction" method="delete">
			<result type="redirect">find.action</result>
			<result name="input">/index.jsp</result>
		</action>
	</package>

</struts>

请问类级的国际化没办法调用什么原因
  • 318c17e2-6230-3d15-ad78-09e284cd0087-thumb
  • 描述: 数据库结构
  • 大小: 20.9 KB
  • 查看次数: 19
  • ssh2.rar (23.6 KB)
  • 描述: struts.jar struts2-spring-plugin-2.0.11.1.jar commons-dbcp.jar commons-pool-1.3.jar 其他照常配置就可以了,事务没有加上
  • 下载次数: 17
  • C8733f36-e1e7-3e2d-8086-72253592b23e-thumb
  • 描述:
  • 大小: 32.2 KB
  • 查看次数: 13
   
论坛首页 Java版 Struts

跳转论坛:
JavaEye推荐
    快速回复 引用上一条消息 (Alt+S)