Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring MVC with XML
    primarykey
    data
    text
    <p>I'm learning SpringMVC via Mkyong.com tutorials. In his tutorials, Maven is used to build the programs.</p> <p>I'm not using Maven to build it in this programs.</p> <p>My Sample Code: </p> <p>Coffee.java</p> <pre><code>package com.springMVC; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "coffee") public class Coffee { String name; int quanlity; public String getName() { return name; } @XmlElement public void setName(String name) { this.name = name; } public int getQuanlity() { return quanlity; } @XmlElement public void setQuanlity(int quanlity) { this.quanlity = quanlity; } public Coffee(String name, int quanlity) { this.name = name; this.quanlity = quanlity; } public Coffee() { } } </code></pre> <p><strong>XMLController.java</strong></p> <pre><code>package com.springMVC; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.springMVC.Coffee; @Controller @RequestMapping("/coffee") public class XMLController { @RequestMapping(value="{name}", method = RequestMethod.GET) public @ResponseBody Coffee getCoffeeInXML(@PathVariable String name) { Coffee coffee = new Coffee(name, 100); return coffee; } </code></pre> <p><strong>mvc-dispacter-servlet.xml</strong></p> <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" 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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt; &lt;context:component-scan base-package="com.springMVC" /&gt; &lt;mvc:annotation-driven /&gt; &lt;/beans&gt; </code></pre> <p><strong>web.xml</strong></p> <pre><code>&lt;web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt; &lt;display-name&gt;Spring Web MVC Application&lt;/display-name&gt; &lt;servlet&gt; &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt; &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/mvc-dispatcher-servlet.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;/web-app&gt; </code></pre> <p><strong><img src="https://i.stack.imgur.com/8RYbb.jpg" alt="my code structure:"></strong></p> <p>Please give me a URI(example:https:\localhost:8080/MVCXML/rest/coffee/arabic) to view an output like in MkYong.com tutorial(<a href="http://www.mkyong.com/spring-mvc/spring-3-mvc-and-xml-example/" rel="nofollow noreferrer">http://www.mkyong.com/spring-mvc/spring-3-mvc-and-xml-example/</a>) </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload