11. Add a member to the integrated SSH framework
1, we write a secret member of the JSP file
<%@ 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" ><?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. Modify Action/** * Features: Integrated SSH framework * author:cutter_point * Time: March 29, 2015 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;//first injected by name, if not found, inject private by type String name;//name public string GetName () {return name;} public void SetName (String name) {this.name = name;} Public String Add () throws Exception{personservice.save (name); return "Add";} Public String list () throws Exception {/*//Gets the instance, method 1ServletContext sc = servletactioncontext.getrequest (). GetSession (). Getservletcontext (); WebapplicationcontextWAC = (webapplicationcontext) sc.getattribute (Webapplicationcontext.root_web_application_context_attribute);// Method 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, OK, let's look at the effectAt the beginning of the database
We insert a data
We click Submit
The results show!!!!!.
All right, then it's over, eh! You're right, it's over, why?? Because there is no garbled!!!
I want to appear in Chinese garbled problem then solve, see how to solve, but it does not appear, we can not force him, well, the end!!!!
"Java EE Spring" 11, add a member of the Integrated SSH framework