I am trying to make simple rest service which is used by everybody example it will consume by mobile developer.so I need to send static data to every one .I am trying to send static this data .
{
name:"abcd"
}
in other word if some one hit my system like this http://ift.tt/1EjpTOT .then user get above json.
I follow this like to make http://ift.tt/1lNSJgc
I follow this step
- download these jar files(-- jackson-annotations-x.x.x.jar -- jackson-core-x.x.x.jar -- jackson-databind-x.x.x.jar) and include in lib folder.
here is my code web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://ift.tt/qzwahU"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/qzwahU
http://ift.tt/16hRdKA">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
hello-servelts.xml
<beans xmlns="http://ift.tt/GArMu6"
xmlns:context="http://ift.tt/GArMu7"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="
http://ift.tt/GArMu6
http://ift.tt/QEDs1e
http://ift.tt/GArMu7
http://ift.tt/QEDs1k">
<context:component-scan base-package="com.tutorialspoint" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
controller.js
package com.tutorialspoint;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/hello")
public class HelloController{
@RequestMapping( method = RequestMethod.GET,headers="Accept=application/json")
public String printHello(ModelMap model) {
return "abcd";
}
}
Aucun commentaire:
Enregistrer un commentaire