Developing Spring MVC Application with JBuilder2005 - and Representation Technique XSLT Integrated Gaoke Hua Author: Gao Jinghua, Nanjing Aviation College computes master's degree in mathematics, more than ten years of corporate information technology work experience. Current research interest, J2EE enterprise application, ERP software research and development, data warehouse system research and development. 1. Establish basic Spring applications according to "Developing Spring MVC Applications with JBuilder2005"
2. Add JDOM, DOM4J class library
3. The source file is as follows, explained in detail, please see the Spring reference document
/src/xslt/homepagecontroller.java
Package XSLT;
Import java.util. *;
Import javax.servlet.http. *;
Import org.apache.commons.logging. *;
Import org.springframework.web.servlet. *;
Import org.springframework.Web.Servlet.mvc. *;
Public Class HomePageController Extends AbstractController {
/ ** Logger for this class and subclasses * /
Protected final log logger = logfactory.getlog (getclass ());
Public ModlandView HandleRequestinternal
HTTPSERVLETREQUEST REQ,
HttpservletResponse Resp) throws Exception {
/ *
Public ModelandView Handlerequest (httpservletRequest Request,
Httpservletresponse response) throws
ServletException, IOException {
* /
Map map = new hashmap ();
List wordlist = new arraylist ();
WordList.Add ("Hello");
WordList.Add ("world");
Map.put ("WordList", WordList);
Return New ModelandView ("HOME", MAP);
}
}
/src/xslt/homepage.java
Package XSLT;
Import java.util. *;
Import javax.servlet.http. *;
Import org.jdom.element;
Import Org.jdom.Output. *;
Import org.springframework.web.servlet.View.xslt. *;
Import org.w3c.dom. *;
// Imports Omitted for BREVITY
Public class homepage extends abstractxsltview {
Protected node createdomNode
Map Model, String Rootname, HTTPSERVLETREQUEST REQ,
HTTPSERVLETRESPONSE RES
"throws exception {
Org.jdom.document doc = new org.jdom.document ();
Element root = new element (rootname);
Doc.setrootElement (root);
List word = (list) Model.get ("wordlist"); for (item it = words.Item (); it.hasnext ();) {
String nextWord = (string) it.next ();
ELEMENT E = New Element ("Word");
E.SetText (Nextword);
Root.addContent (e);
}
// Convert Jdom Doc to a W3C Node and Return
Return New Domoutputter (). Output (DOC);
}
}
/Web-inf/classes/views.properties
Home.class = xslt.homepage
Home.stylesheetLocation = / Web-inf / xsl / home.xslt
Home.Root = Words
/Web-inf/xsl/home.xslt
XML Version = "1.0"?>
xsl: for-energy>
body>
html>
xsl: template>
xsl: stylesheet>
/Web-inf/springapp-servlet.xml
XML Version = "1.0" encoding = "UTF-8"?>
beans>