1

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.

7
  • 1
    I think not a relevant questions u have asked.. Please clarify ur questions and explain what do u want to achieve actually Commented 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. Commented 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 bit Commented Feb 16, 2016 at 12:56
  • 1
    You 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 Spring Commented 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? Commented Feb 16, 2016 at 13:05

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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?

1 Comment

Lets put it this way. In my controller i only want to handle post requests coming from the website. I don't want to show any view from my java code. Actually i don't need MVC structure either. I am a little bit lost sorry for the confusing explanation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.