get an html page using JAXRS










2















I am a Java developer, I want to write my own blogging application (that bloggers use to write their blogs with) i know it may sound crazy but i want it just for learning purpose, i am using JSF EJB Hibernate and RESTeasy tools,i started it i have created the database and the view.



From the information that i collected it is recommended to store the blog content in database(in html text), i find that i can use for that Javascript editor like CKEditor after the blogger write his blog in CKEditor i will concatenate it with a prepared header and footer after that i will store it in the database, and i found out that i can get blog post using RESTeasy API.



As an example(sorry):
after the blog is stored in the database
i want to present it to visitors like this:



  • link containing a path and the id of the article




<div>
<a href="/article/id">Read More...</a>
</div>




when the visitor press the link a REST Controller handle the request, fetch the article from the database using the provided id in the link and return an html page (without creating it statically).

The RESTeasy part perhaps something like this:



@Stateless
@Path("/article/")
public class ArticleResource

@EJB
private ArticleService articleService;

@GET
@Path("/id")
@Produces(value = MediaType.TEXT_HTML)
public Response getArticleById(@PathParam("id") Long id)
//get article post from the database
Article article = articleService.findById(id);
//something here i didn't know
//return article post as an html page





Please if there is anything here that you see is wrong feel free to inform me, i am just learning here. And if there is an even better approach that you see is good, i really appreciate it.



I know perhaps using Spring it can be better but i want just to learn here how to do it.



I want to know how to get an html page stored in database using JAXRS,
the html page has no file in the application it is just stored in the database something like this:



"<html><head>...</head> <body>...content of the blog here</body> </html>"


Thank you in advance.










share|improve this question






















  • Updated my answer with jersey MVC

    – user7294900
    Nov 14 '18 at 16:13











  • @user7294900 Oops, I didn't even read that the OP is using RESTeasy. I'm looking through the RESTEasy docs and can't find any MVC feature. I don't know if the Jersey MVC module will work with RESTEasy. Sorry.

    – Paul Samsotha
    Nov 14 '18 at 18:20












  • Here's an example that mixes RESTEasy and Spring MVC. It looks like an official example from the RESTeasy GitHub org.

    – Paul Samsotha
    Nov 14 '18 at 18:27















2















I am a Java developer, I want to write my own blogging application (that bloggers use to write their blogs with) i know it may sound crazy but i want it just for learning purpose, i am using JSF EJB Hibernate and RESTeasy tools,i started it i have created the database and the view.



From the information that i collected it is recommended to store the blog content in database(in html text), i find that i can use for that Javascript editor like CKEditor after the blogger write his blog in CKEditor i will concatenate it with a prepared header and footer after that i will store it in the database, and i found out that i can get blog post using RESTeasy API.



As an example(sorry):
after the blog is stored in the database
i want to present it to visitors like this:



  • link containing a path and the id of the article




<div>
<a href="/article/id">Read More...</a>
</div>




when the visitor press the link a REST Controller handle the request, fetch the article from the database using the provided id in the link and return an html page (without creating it statically).

The RESTeasy part perhaps something like this:



@Stateless
@Path("/article/")
public class ArticleResource

@EJB
private ArticleService articleService;

@GET
@Path("/id")
@Produces(value = MediaType.TEXT_HTML)
public Response getArticleById(@PathParam("id") Long id)
//get article post from the database
Article article = articleService.findById(id);
//something here i didn't know
//return article post as an html page





Please if there is anything here that you see is wrong feel free to inform me, i am just learning here. And if there is an even better approach that you see is good, i really appreciate it.



I know perhaps using Spring it can be better but i want just to learn here how to do it.



I want to know how to get an html page stored in database using JAXRS,
the html page has no file in the application it is just stored in the database something like this:



"<html><head>...</head> <body>...content of the blog here</body> </html>"


Thank you in advance.










share|improve this question






















  • Updated my answer with jersey MVC

    – user7294900
    Nov 14 '18 at 16:13











  • @user7294900 Oops, I didn't even read that the OP is using RESTeasy. I'm looking through the RESTEasy docs and can't find any MVC feature. I don't know if the Jersey MVC module will work with RESTEasy. Sorry.

    – Paul Samsotha
    Nov 14 '18 at 18:20












  • Here's an example that mixes RESTEasy and Spring MVC. It looks like an official example from the RESTeasy GitHub org.

    – Paul Samsotha
    Nov 14 '18 at 18:27













2












2








2








I am a Java developer, I want to write my own blogging application (that bloggers use to write their blogs with) i know it may sound crazy but i want it just for learning purpose, i am using JSF EJB Hibernate and RESTeasy tools,i started it i have created the database and the view.



From the information that i collected it is recommended to store the blog content in database(in html text), i find that i can use for that Javascript editor like CKEditor after the blogger write his blog in CKEditor i will concatenate it with a prepared header and footer after that i will store it in the database, and i found out that i can get blog post using RESTeasy API.



As an example(sorry):
after the blog is stored in the database
i want to present it to visitors like this:



  • link containing a path and the id of the article




<div>
<a href="/article/id">Read More...</a>
</div>




when the visitor press the link a REST Controller handle the request, fetch the article from the database using the provided id in the link and return an html page (without creating it statically).

The RESTeasy part perhaps something like this:



@Stateless
@Path("/article/")
public class ArticleResource

@EJB
private ArticleService articleService;

@GET
@Path("/id")
@Produces(value = MediaType.TEXT_HTML)
public Response getArticleById(@PathParam("id") Long id)
//get article post from the database
Article article = articleService.findById(id);
//something here i didn't know
//return article post as an html page





Please if there is anything here that you see is wrong feel free to inform me, i am just learning here. And if there is an even better approach that you see is good, i really appreciate it.



I know perhaps using Spring it can be better but i want just to learn here how to do it.



I want to know how to get an html page stored in database using JAXRS,
the html page has no file in the application it is just stored in the database something like this:



"<html><head>...</head> <body>...content of the blog here</body> </html>"


Thank you in advance.










share|improve this question














I am a Java developer, I want to write my own blogging application (that bloggers use to write their blogs with) i know it may sound crazy but i want it just for learning purpose, i am using JSF EJB Hibernate and RESTeasy tools,i started it i have created the database and the view.



From the information that i collected it is recommended to store the blog content in database(in html text), i find that i can use for that Javascript editor like CKEditor after the blogger write his blog in CKEditor i will concatenate it with a prepared header and footer after that i will store it in the database, and i found out that i can get blog post using RESTeasy API.



As an example(sorry):
after the blog is stored in the database
i want to present it to visitors like this:



  • link containing a path and the id of the article




<div>
<a href="/article/id">Read More...</a>
</div>




when the visitor press the link a REST Controller handle the request, fetch the article from the database using the provided id in the link and return an html page (without creating it statically).

The RESTeasy part perhaps something like this:



@Stateless
@Path("/article/")
public class ArticleResource

@EJB
private ArticleService articleService;

@GET
@Path("/id")
@Produces(value = MediaType.TEXT_HTML)
public Response getArticleById(@PathParam("id") Long id)
//get article post from the database
Article article = articleService.findById(id);
//something here i didn't know
//return article post as an html page





Please if there is anything here that you see is wrong feel free to inform me, i am just learning here. And if there is an even better approach that you see is good, i really appreciate it.



I know perhaps using Spring it can be better but i want just to learn here how to do it.



I want to know how to get an html page stored in database using JAXRS,
the html page has no file in the application it is just stored in the database something like this:



"<html><head>...</head> <body>...content of the blog here</body> </html>"


Thank you in advance.






<div>
<a href="/article/id">Read More...</a>
</div>





<div>
<a href="/article/id">Read More...</a>
</div>






java jax-rs blogs resteasy






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 8:57









magran xmagran x

264




264












  • Updated my answer with jersey MVC

    – user7294900
    Nov 14 '18 at 16:13











  • @user7294900 Oops, I didn't even read that the OP is using RESTeasy. I'm looking through the RESTEasy docs and can't find any MVC feature. I don't know if the Jersey MVC module will work with RESTEasy. Sorry.

    – Paul Samsotha
    Nov 14 '18 at 18:20












  • Here's an example that mixes RESTEasy and Spring MVC. It looks like an official example from the RESTeasy GitHub org.

    – Paul Samsotha
    Nov 14 '18 at 18:27

















  • Updated my answer with jersey MVC

    – user7294900
    Nov 14 '18 at 16:13











  • @user7294900 Oops, I didn't even read that the OP is using RESTeasy. I'm looking through the RESTEasy docs and can't find any MVC feature. I don't know if the Jersey MVC module will work with RESTEasy. Sorry.

    – Paul Samsotha
    Nov 14 '18 at 18:20












  • Here's an example that mixes RESTEasy and Spring MVC. It looks like an official example from the RESTeasy GitHub org.

    – Paul Samsotha
    Nov 14 '18 at 18:27
















Updated my answer with jersey MVC

– user7294900
Nov 14 '18 at 16:13





Updated my answer with jersey MVC

– user7294900
Nov 14 '18 at 16:13













@user7294900 Oops, I didn't even read that the OP is using RESTeasy. I'm looking through the RESTEasy docs and can't find any MVC feature. I don't know if the Jersey MVC module will work with RESTEasy. Sorry.

– Paul Samsotha
Nov 14 '18 at 18:20






@user7294900 Oops, I didn't even read that the OP is using RESTeasy. I'm looking through the RESTEasy docs and can't find any MVC feature. I don't know if the Jersey MVC module will work with RESTEasy. Sorry.

– Paul Samsotha
Nov 14 '18 at 18:20














Here's an example that mixes RESTEasy and Spring MVC. It looks like an official example from the RESTeasy GitHub org.

– Paul Samsotha
Nov 14 '18 at 18:27





Here's an example that mixes RESTEasy and Spring MVC. It looks like an official example from the RESTeasy GitHub org.

– Paul Samsotha
Nov 14 '18 at 18:27












1 Answer
1






active

oldest

votes


















1














Use Jersey's MVC Templates



You can use freemarker as template engine to produce HTML with context



Your template will be similar to:



<html><head>...</head> <body> $article.toString()</body> </html>


You can follow example:




In this example, the FruitResource JAX-RS resource class is the controller. The Viewable instance encapsulates the referenced data model which is a simple String.



Furthermore, we also include a named reference to the associated view template – index.ftl.



In this example, we’ve used the @Template annotation. This avoids wrapping our model directly in a template reference via Viewable and makes our resource method more readable.







share|improve this answer

























  • thank you for your answer i will give it a try and come back at you

    – magran x
    Nov 14 '18 at 9:25











  • @PaulSamsotha edited answer

    – user7294900
    Nov 14 '18 at 15:23











  • @PaulSamsotha updated answer

    – user7294900
    Nov 14 '18 at 16:13










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296289%2fget-an-html-page-using-jaxrs%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Use Jersey's MVC Templates



You can use freemarker as template engine to produce HTML with context



Your template will be similar to:



<html><head>...</head> <body> $article.toString()</body> </html>


You can follow example:




In this example, the FruitResource JAX-RS resource class is the controller. The Viewable instance encapsulates the referenced data model which is a simple String.



Furthermore, we also include a named reference to the associated view template – index.ftl.



In this example, we’ve used the @Template annotation. This avoids wrapping our model directly in a template reference via Viewable and makes our resource method more readable.







share|improve this answer

























  • thank you for your answer i will give it a try and come back at you

    – magran x
    Nov 14 '18 at 9:25











  • @PaulSamsotha edited answer

    – user7294900
    Nov 14 '18 at 15:23











  • @PaulSamsotha updated answer

    – user7294900
    Nov 14 '18 at 16:13















1














Use Jersey's MVC Templates



You can use freemarker as template engine to produce HTML with context



Your template will be similar to:



<html><head>...</head> <body> $article.toString()</body> </html>


You can follow example:




In this example, the FruitResource JAX-RS resource class is the controller. The Viewable instance encapsulates the referenced data model which is a simple String.



Furthermore, we also include a named reference to the associated view template – index.ftl.



In this example, we’ve used the @Template annotation. This avoids wrapping our model directly in a template reference via Viewable and makes our resource method more readable.







share|improve this answer

























  • thank you for your answer i will give it a try and come back at you

    – magran x
    Nov 14 '18 at 9:25











  • @PaulSamsotha edited answer

    – user7294900
    Nov 14 '18 at 15:23











  • @PaulSamsotha updated answer

    – user7294900
    Nov 14 '18 at 16:13













1












1








1







Use Jersey's MVC Templates



You can use freemarker as template engine to produce HTML with context



Your template will be similar to:



<html><head>...</head> <body> $article.toString()</body> </html>


You can follow example:




In this example, the FruitResource JAX-RS resource class is the controller. The Viewable instance encapsulates the referenced data model which is a simple String.



Furthermore, we also include a named reference to the associated view template – index.ftl.



In this example, we’ve used the @Template annotation. This avoids wrapping our model directly in a template reference via Viewable and makes our resource method more readable.







share|improve this answer















Use Jersey's MVC Templates



You can use freemarker as template engine to produce HTML with context



Your template will be similar to:



<html><head>...</head> <body> $article.toString()</body> </html>


You can follow example:




In this example, the FruitResource JAX-RS resource class is the controller. The Viewable instance encapsulates the referenced data model which is a simple String.



Furthermore, we also include a named reference to the associated view template – index.ftl.



In this example, we’ve used the @Template annotation. This avoids wrapping our model directly in a template reference via Viewable and makes our resource method more readable.








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 16:13

























answered Nov 14 '18 at 9:06









user7294900user7294900

22.9k113362




22.9k113362












  • thank you for your answer i will give it a try and come back at you

    – magran x
    Nov 14 '18 at 9:25











  • @PaulSamsotha edited answer

    – user7294900
    Nov 14 '18 at 15:23











  • @PaulSamsotha updated answer

    – user7294900
    Nov 14 '18 at 16:13

















  • thank you for your answer i will give it a try and come back at you

    – magran x
    Nov 14 '18 at 9:25











  • @PaulSamsotha edited answer

    – user7294900
    Nov 14 '18 at 15:23











  • @PaulSamsotha updated answer

    – user7294900
    Nov 14 '18 at 16:13
















thank you for your answer i will give it a try and come back at you

– magran x
Nov 14 '18 at 9:25





thank you for your answer i will give it a try and come back at you

– magran x
Nov 14 '18 at 9:25













@PaulSamsotha edited answer

– user7294900
Nov 14 '18 at 15:23





@PaulSamsotha edited answer

– user7294900
Nov 14 '18 at 15:23













@PaulSamsotha updated answer

– user7294900
Nov 14 '18 at 16:13





@PaulSamsotha updated answer

– user7294900
Nov 14 '18 at 16:13



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296289%2fget-an-html-page-using-jaxrs%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus