I have a spring mvc application which i use as only a server. I have deployed some html and javascript files on my hosting account and sending post requests to my server only. Retrieve data from database and send back the data to the html or javascript pages. I don't use any servlets,jsp or jsf. Everywhere i look it says that i should use them however. Am i doing something wrong? It feels like bad practice but i don't know the right way to do it i guess. Any help would be appreciated.
-
1I think not a relevant questions u have asked.. Please clarify ur questions and explain what do u want to achieve actuallyVikrant Kashyap– Vikrant Kashyap2016-02-16 12:51:15 +00:00Commented Feb 16, 2016 at 12:51
-
I have a spring mvc application which i use as only a server. i am sure you have a wrong understanding about MVC architecture.Jai– Jai2016-02-16 12:56:39 +00:00Commented Feb 16, 2016 at 12:56
-
@Vikrant Kashyap I dont want an mvc structure actually i want a plain server that gets post messages from my website and processes them then returns the value to website. I dont want to use jsp jsf or servlets in my application. Just plain server. But i think i don't know how to achieve this in Spring. I don't know what i should search for either. Can you help a little bitmert– mert2016-02-16 12:56:45 +00:00Commented Feb 16, 2016 at 12:56
-
1You mean you don't need any View layer like jsp or html? and your server should respond back to HTTP requests with a json/xml output. which is what you are asking I guess? You can look into Building a RESTful Web Service in SpringLucky– Lucky2016-02-16 13:03:08 +00:00Commented Feb 16, 2016 at 13:03
-
@Lucky Yep thats correct. I couldnt find any resource on the web though all the examples are related to mvc structure. How can i achieve that?mert– mert2016-02-16 13:05:53 +00:00Commented Feb 16, 2016 at 13:05
2 Answers
As I already mentioned in my comments, you can look into creating a webservice. Since you are using Spring already, try this guide on Building a RESTful Web Service.
After creating the service, you can call it up like this, where you pass in input parameters to your rest endpoints,
http://localhost:8080/greeting?name=User
Now your service will respond back to your GET request and you'll be output a JSON/xml string which you can process later at the client side. The sample json response looks like this,
{"id":1,"content":"Hello, User!"}
Here's another example blog article on Spring Restful Web Service Example with JSON, Jackson and Client Program
Comments
Well, I think you should first expand your question a bit since one needs to assume a lot to give you an answer.
IMO, JSF is not great and there are other better options for UI and JSPs are dead. But I'm biased since I used last time JSF 1.X and then went with Spring MVC and Angular or Spring and Apache Wicket more recently.
I used for instance Spring MVC to implement an HTTP RPC API with JSON payloads to which an Angular frontend connected and it worked just fine. I also had the feeling that everyone is doing that nowadays:).
I also guess you are using at least one servlet to configure Spring DispatcherServlet. Right?