STRUTS2 Convention plugin trial + spring+hibernate SSH integration

Source: Internet
Author: User
Tags i18n

The first step is to introduce Struts2-convention-plugin-2.2.1.jar

Then, change the configuration file.

I changed it in the Struts.properties file:

Struts.objectfactory = Springstruts.devmode = truestruts.i18n.encoding = Utf-8struts.convention.result.path =/web-inf /jsp/struts.convention.package.locators = Action,actions,struts,struts2,control,controls, Teststruts.convention.action.suffix =action,control

The first line. Integration with spring.

The second line, enable the Struts development mode. Easy to Debug.

Line three, i18n.

Row four, specify the path to the default view, and all view resources will be searched from this path.

Line Five. Specifies the package name for the search. Because the individual likes to name the package of the control class as *.control, add the controls package. Add the test package again

Line Six. Specifies the end of file name for the class file. For example, the default is to search only the abcaction category. It is now possible to search for this kind of abccontrol.


Java test Code (partial) project address: http://localhost:8080/Photo/

Package Com.lgh.test;import Java.util.list;import Org.apache.struts2.servletactioncontext;import Org.apache.struts2.convention.annotation.namespace;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.context.annotation.Scope; Import Org.springframework.stereotype.controller;import Org.apache.struts2.convention.annotation.actions;import Org.apache.struts2.convention.annotation.result;import Org.apache.struts2.convention.annotation.results;import Com.lgh.common.tools.json.jsonutil;import com.lgh.sys.entity.user;import com.opensymphony.xwork2.Action; @Scope (" Prototype ") @Controller @namespace ("/name ")//Specify namespace public class TestControl implements Action {@Autowiredprivate Testservice testservice;private User user;private string name;private list<user> list;public string GetName () { return name; public void SetName (String name) {this.name = name;} Public User GetUser () {return user;}        public void SetUser (user user) {this.user = user;} Http://localhOst:8080/photo/name/test is able to access this action@org.apache.struts2.convention.annotation.action (value = "Test", results = {@ Result (name = "Success", location = "/index.jsp", type = "Redirect"), @Result (name = "Register", location = "/haha.jsp", Ty PE = "redirect")}) public String test () throws Exception {List = Testservice.findbysome ("1", user.class); User = Testservic E.findbysome ("1", User.class). Get (0); name = User.getname (); Jsonutil.outtojson (Servletactioncontext.getresponse (), user); return SUCCESS;} Http://localhost:8080/Photo/haha/register can access this action note here that value begins with a slash "/" to indicate an absolute path. Namespace Invalid @org.apache.struts2.convention.annotation.action (value = "/haha/register", results = {@Result (name = " Success ", location ="/index.jsp ", type =" Redirect "), @Result (name =" Register ", location ="./haha.jsp ", type =" redirect ")})//run will jump to http://localhost:8080/Photo/haha/haha.jsp./haha.jsp and Direct write haha.jsp effect, but after writing/haha.jsp, will jump to http:// localhost:8080/photo/haha.jsp similar to absolute path public String Register () throws Exception {List = Testservice.findbysome ("1", user.class), User = Testservice.findbysome ("1", User.class). Get (0); name = User.getname ();//Jsonutil.outtojson (Servletactioncontext.getresponse (), user); return "register";} @Overridepublic String Execute () throws Exception {//TODO auto-generated method Stubreturn null;}}

After SSH Integrated Framework download, please import with MyEclipse.

MySQL's driver and jackson1.9.11-all jar packages are not uploaded. Please search for the download yourself.

http://download.csdn.net/detail/lgh06/8039749 free points.

The writing is more rotten, forgive me ...

STRUTS2 Convention plugin trial + spring+hibernate SSH integration

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.