"Java EE Spring" 11, add a member of the Integrated SSH framework

Source: Internet
Author: User

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 effect

At 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.