Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

java - How to return actual html file using JAX-RS

so far, I'm returning html my home page by:

@GET
@Produces({MediaType.TEXT_HTML})
public String viewHome()
{
   return "<html>...</html>";
}

what I want to do is return home.html itself and not copying its contents and returning the string instead.

How do I do this? thanks :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can just return an instance of java.io.InputStream or java.io.Reader — JAX-RS will do the right thing.

@GET
@Produces({MediaType.TEXT_HTML})
public InputStream viewHome()
{
   File f = getFileFromSomewhere();
   return new FileInputStream(f);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...