A
A
Anna2017-02-22 18:04:17
Java
Anna, 2017-02-22 18:04:17

How to write a web interface for a Java server?

Good afternoon! I apologize in advance for a possibly stupid question.
There is a server in Java, compiled from under Eclipse using maven (JPA project). So far, only api has been written (it was developed for a mobile application). I also want to throw in a couple of html pages so that they receive data and, for example, at the request <path to the server>/page.html, they give out a minimal interface. Question: Where should they be placed? Or do I need to create a completely new project (like a JSP) and run it as well?
Part of the project: 59efd-clip-7kb.png?nocache=1
GET request example:

@GET
@Path("/")
@Override
public Response getAll() {
      return this.respond(DataStore.getInstance().getAllEntities(Game.class));
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vorh, 2017-02-22
@annaoomph

1) Are you going to develop the admin panel in the future?
If so, it's better to separate the frontend and backend sides into different projects, for the frontend use some popular JS framework like Angular,2 , React and etc , which will allow you to conveniently develop new functionality and work with your server through the rest
2) If you need to quickly and with a minimum of costs, then generate a jsp template on the required request and return it, do not forget about security and fasten a simple authorization through Spring Security , for example
How to return html?
1) Java Servlet

public class SimpleServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
 RequestDispatcher view = req.getRequestDispatcher("/path/to/file.html");
        view.forward(req, resp);    
    }
}

2) Rapidoid
On.get("/main").html((Req req) -> {
    Resp resp = req.response();
    resp.contentType(MediaType.HTML_UTF_8);
    resp.result('Main.html');
    return resp;
});

3) Spring
can wrap once in JSP and cast it
@RequestMapping(value = "/main", method = RequestMethod.GET)
public ModelAndView getMain()
    ModelAndView modelAndview   = new ModelAndView("success.jsp");
    return modelAndView;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question