This post will describe to work with spring and xslt.
1. open Eclipse and create a dynamic webproject - provide name as spring-xslt(you can give what ever name you want)
2. After that select the target runtime environment(ex: location of tomcat or Jboss or respective server)
3. open web.xml which already created by eclipse for you, modify as mentioned below.
4. After that create simple-servlet.xml like mentioned below and put inside WEB-INF
6. Now Need to create Contoller class by extending AbstractCommandController.
home.(class)=com.siva.HomePage
home.stylesheetLocation=/WEB-INF/xsl/home.xslt
home.root=words
9.finally create one index.html or jsp to submit the form.
<body>
<form action="login.htm" name="login">
Word Id :<input type="text" value="" name="wordId">
Word NAME :<input type="text" value="" name="wordName">
<input type="submit" value="submit">
</form>
</body>
Above mentioned html/jsp is for to submit the form, if we required fileds need to be eneterd by the user then we have to get that values from command object, and then needs to process.
10. Now Everthing is completed. Once you configured and copied the above code into respective places.
We can exceuting the application and can able to see the results.
11. for this project required jars are..
commons-logging-1.1.1.jar
log4j-1.2.15.jar
spring-2.5.6.jar
spring-beans.jar
spring-webmvc.jar
jdom-1.0.jar
1. open Eclipse and create a dynamic webproject - provide name as spring-xslt(you can give what ever name you want)
2. After that select the target runtime environment(ex: location of tomcat or Jboss or respective server)
3. open web.xml which already created by eclipse for you, modify as mentioned below.
<web-app id="WebApp_ID" version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>spring-xslt</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</div>
<servlet>
<servlet-name>simple</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>simple</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
4. After that create simple-servlet.xml like mentioned below and put inside WEB-INF
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" > <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver" > <property name="order"><value>1</value></property> <property name="basename" value="views" /> </bean> <bean id="xsltViewResolver" class="org.springframework.web.servlet.view.xslt.XsltViewResolver" > <property name="order"><value>2</value></property> <property name="viewClass" value="org.springframework.web.servlet.view.xslt.XsltView" /> <property name="sourceKey" value="obj" /> <property name="suffix" value=".xsl" /> <property name="prefix" value="/WEB-INF/xsl/" /> </bean> <bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" > <property name="mappings" > <value> /login.htm=myxsl </value> </property> </bean> <bean id="myxsl" class="com.siva.HomePageController" /> <!--<bean id="myxsl" class="com.siva.XsltDisplayController" /> --></beans>5. Now we have to create xslt file under /WEB-INF/xsl/home.xslt and place the below mentioned code
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" omit-xml-declaration="yes"/> <xsl:template match="/"> <html> <head><title>Hello!</title></head> <body> <h1>My First Words</h1> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="word"> <xsl:value-of select="."/><br/> </xsl:template> </xsl:stylesheet>
6. Now Need to create Contoller class by extending AbstractCommandController.
package com.siva; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; public class HomePageController extends AbstractController{ protected ModelAndView handleRequestInternal( HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); List wordList = new ArrayList(); wordList.add("hello"); wordList.add("world"); map.put("wordList", wordList); return new ModelAndView("home", map); } }7. Need to create xslt view class to iterate the xslt elements.
package com.siva; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; import org.springframework.web.servlet.view.xslt.AbstractXsltView; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Text; public class HomePage extends AbstractXsltView { protected Source createXsltSource(Map model, String rootName, HttpServletRequest request, HttpServletResponse response) throws Exception { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element root = document.createElement(rootName); List words = (List) model.get("wordList"); for (Iterator it = words.iterator(); it.hasNext();) { String nextWord = (String) it.next(); Element wordNode = document.createElement("word"); Text textNode = document.createTextNode(nextWord); wordNode.appendChild(textNode); root.appendChild(wordNode); } return new DOMSource(root); } }8.Create views.properties file under WEB-INF/classes/views.properties
home.(class)=com.siva.HomePage
home.stylesheetLocation=/WEB-INF/xsl/home.xslt
home.root=words
9.finally create one index.html or jsp to submit the form.
<body>
<form action="login.htm" name="login">
Word Id :<input type="text" value="" name="wordId">
Word NAME :<input type="text" value="" name="wordName">
<input type="submit" value="submit">
</form>
</body>
Above mentioned html/jsp is for to submit the form, if we required fileds need to be eneterd by the user then we have to get that values from command object, and then needs to process.
10. Now Everthing is completed. Once you configured and copied the above code into respective places.
We can exceuting the application and can able to see the results.
11. for this project required jars are..
commons-logging-1.1.1.jar
log4j-1.2.15.jar
spring-2.5.6.jar
spring-beans.jar
spring-webmvc.jar
jdom-1.0.jar
it looked interesting, but it's not even worth reading with such formatting
ReplyDeleteseriously, do you expecty anyone to look for all those jars? dependency resolution? does that ring a bell?
ReplyDeleteMay you attached your example?
ReplyDeleteThanks
try to implement this code and it gave me many errors
ReplyDeleteAbstractXsltView is deprecated.
ReplyDeletehttp://docs.spring.io/spring/docs/3.0.x/api/org/springframework/web/servlet/view/xslt/AbstractXsltView.html
Do you have an example that uses XsltView? That Spring suggests.
That is really fascinating, You're an excessively professional blogger. I've joined your rss feed and sit up for in the hunt for more of your great post. Additionally, I have shared your site in my social networks gmail email login
ReplyDeleteThanks for that..
Deleteqweewwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
ReplyDeletewonderful article contains lot of valuable information. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
ReplyDeleteAWS course in Chennai
Good content. You write beautiful things.
ReplyDeletesportsbet
vbet
hacklink
hacklink
sportsbet
mrbahis
vbet
mrbahis
taksi
Good text Write good content success. Thank you
ReplyDeletebonus veren siteler
kibris bahis siteleri
slot siteleri
tipobet
betpark
poker siteleri
betmatik
mobil ödeme bahis
elf bar
ReplyDeletebinance hesap açma
sms onay
6TUBU
Finally, Directory for Places is more than just a directory of places, it's a community of travelers and adventurers. https://bit.ly/directory-for-places The platform allows users to connect with like-minded individuals, share their experiences, and discover new and exciting destinations together.
ReplyDeleteA business guide provides information and guidance on various aspects of business management and ownership.
https://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
74M4
EskiÅŸehir
ReplyDeleteDenizli
Malatya
Diyarbakır
Kocaeli
03ZZ0
Diyarbakır
ReplyDeleteKırklareli
Kastamonu
Siirt
Diyarbakır
RTH
https://titandijital.com.tr/
ReplyDeleteısparta parça eşya taşıma
ankara parça eşya taşıma
izmir parça eşya taşıma
diyarbakır parça eşya taşıma
UEFP
giresun evden eve nakliyat
ReplyDeletebalıkesir evden eve nakliyat
maraÅŸ evden eve nakliyat
kastamonu evden eve nakliyat
kocaeli evden eve nakliyat
H82
40A24
ReplyDeleteCoin MadenciliÄŸi Siteleri
Mexc Borsası Güvenilir mi
Clubhouse Takipçi Satın Al
Binance Komisyon Ne Kadar
Bitcoin MadenciliÄŸi Siteleri
Twitter Trend Topic Hilesi
Linkedin Takipçi Satın Al
Periscope Takipçi Hilesi
Coin Ãœretme Siteleri
7255D
ReplyDeleteücretli canlı show
D2C34
ReplyDeletegörüntülü şov
312602D115
ReplyDeletebufalo içecek
whatsapp görüntülü show güvenilir
ereksiyon hapı
novagra
canli cam show
geciktirici
degra
cobra vega
ücretli show