How to integrate a website with a Java back end?

17,780

Solution 1

You can use a number of technologies to interact with applications. If you want to stay on the Java side, JSF, JSP are two big ones. JSF Depends on a big framework, but there are other frameworks that rely just on JSP/Servlets. You can incorporate JQuery into the HTML/JSP/JSF combinations.

On the other hand you could just use JQuery to send AJAX calls to Servlets that return HTML/Json to the client. The JQuery can then do whatever you want with that.

Solution 2

For the new hotness hook your jQuery up to a Java JAX-RS backend using Jersey. Will work very well with jQuery AJAX.

For example, create a POJO like this:

@Path("/users")
public class UsersService {

    @GET
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public Users getUsers() {
        return UserQuery.getUsers();
    }
}

That says this "service" can provide the UserList in either XML or JSON. Which you can then access via jQuery like this:

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>User List</title>
    <link href="css/base.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <h1>User List</h1>
    <div>
        <ul id="userlist">
        </ul>
    </div>
</body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
    $.getJSON("service/users",
        function(data){
        $.each(data.users, function(i,user){
            $("#userlist").append("<li>"+user.email+"</li>");
        });
        });

</script>
</html>

Simples.

Solution 3

check my question that asks for something similar, as it is very insightful:

Web User Interface for a Java application

Share:
17,780
HyderA
Author by

HyderA

Updated on June 19, 2022

Comments

  • HyderA
    HyderA almost 2 years

    Is JSF the only option?

    The HTML front end uses JQuery as a front-end scripting framework.