【j2ee spring】11、整合SSH框架之添加一个成员
来源:互联网 发布:淘宝网店铺装修 编辑:程序博客网 时间:2024/05/22 10:33
11、整合SSH框架之添加一个成员
1、我们写一个天机成员的jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>SSH之人物添加列表</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <s:form action="Action_add" method="post"> 名字:<s:textfield name="name" /> <input type="submit" value="提交" /> </s:form> </body></html>
2、修改Struts.xml文件
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><!-- <constant name="struts2.ObjectFactory" value="Spring" /> --><package name="person" namespace="/page" extends="struts-default"><action name="Action_*" class="PersonAction" method="{1}"><result name="list">/page/personlist.jsp</result><result name="add">/page/addperson.jsp</result></action></package></struts>
3、修改action
/** * 功能:集成ssh框架 * author:cutter_point * 时间:2015年3月29日17:30:07 */package cn.cutter_point.web.action;import javax.annotation.Resource;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import org.apache.struts2.ServletActionContext;import org.springframework.web.context.WebApplicationContext;import org.springframework.web.context.support.WebApplicationContextUtils;import cn.cutter_point.bean.Person;import cn.cutter_point.service.PersonService;import com.opensymphony.xwork2.ActionSupport;public class PersonAction extends ActionSupport {@Resource private PersonService personService;//先按名字注入,如果找不到的话就按类型注入private String name;//名字public String getName() {return name;}public void setName(String name) {this.name = name;}public String add() throws Exception{personService.save(new Person(name));return "add";}public String list() throws Exception {/*//获取实例,方法1ServletContext sc = ServletActionContext.getRequest().getSession().getServletContext();WebApplicationContext wac = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);//方法2WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());if(wac == webApplicationContext){System.out.println("ok!!!");}PersonService personService = (PersonService) wac.getBean("personServiceBean");*/HttpServletRequest request = ServletActionContext.getRequest();request.setAttribute("persons", personService.getPersons());return "list";}}
4、好的,我们接下来看看效果
开始的时候数据库中
我们插入一个数据
我们点击提交
结果显示出来了!!!!!
好吧,那就结束吧,恩!你没看错,就是结束了,为什么??因为没有出现乱码!!!
我是想出现中文乱码问题那就解决一下,看看如何解决的,但是它不出现,我们不能强迫他,恩,结束了!!!!
0 0
- 【j2ee spring】11、整合SSH框架之添加一个成员
- ssh框架整合之spring整合
- 【j2ee spring】8、整合SSH框架(1)
- 【j2ee spring】9、整合SSH框架(2)
- 【j2ee spring】10、整合SSH框架(3)
- 【j2ee spring】12、整合SSH框架(终结版)
- SSH框架整合之Struts2和Spring整合
- SSH框架整合之Spring和Hibernate整合
- SSH框架搭建过程---之Struts整合Spring框架(4)
- J2ee之SSH框架搭建
- SSH框架spring整合hibernate
- SSH框架搭建过程---之Spring-Hibernate整合(5)
- SSH框架整合之Spring配置(applicationContext)
- SSH框架之spring整合javamail实现邮件服务
- 基于SSH实现管理系统之框架整合篇 5 Spring整合Hibernate框架
- SSH框架整合(Spring整合Struts2,和Spring整合Hibernate)
- SSH整合之框架搭建
- SSH整合之框架搭建 .
- LBS的球面距离计算及Geohash方案探讨(LBS之一)
- MFC编程学习经验一
- 使用JSONExport生成model文件
- HDU 1213 How Many Tables
- 关于斐波那契数列的递推与递归实现
- 【j2ee spring】11、整合SSH框架之添加一个成员
- php数组用法 与 常用数组函数
- bzoj 3916: [Baltic2014]friends
- 结构体内存对齐
- thinkphp
- poj 2135 费用流
- AVAudioPlayer进入后台播放
- FFMPEG 源码分析
- php 常用时间函数