请参阅网页中的JAR文件中 [英] Refer to a web page inside a jar file

查看:142
本文介绍了请参阅网页中的JAR文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作项目。它包括另外一个项目它与REST作为休息-api.jar文件的交易。

I have a working project. It includes another project which deals with REST as a rest-api.jar.

现在我已经做了这个REST API的单页UI上AngularJS,并提供它的主要应用。

Now I have done an one-page UI for this REST API on AngularJS and provided it for the main app.

问题是,我无法找到一种方法,是指从主项目这个页面,因为该页面必须是rest_api.jar内

The problem is that I cannot find a way to refer to this page from the main project because this page MUST be within the rest_api.jar

这是一种方法,我解决了它。简单地重定向到一个页面:

This is a way I solved it. Simply redirecting to a page:

@GET
@Produces(MediaType.TEXT_HTML)
public void doGetAsHtml(@Context
UriInfo info, @Context
HttpServletResponse servletResponse) throws IOException
{
    servletResponse.sendRedirect("/web/pages/index.html");
}

那么,是不是可以参考一个网页,里面的项目jar文件之一,这可怎么实现?

So, is it possible to refer to a web page that is inside one of your project jar files and how this can be achieved?

每一个答案是高度AP preciated和immidiately回应。

Every answer is highly appreciated and responded immidiately.

感谢您。

推荐答案

这要看你说'是指'的意思。

It depends what you mean by 'refer to'.

您可以打开一个文件,该文件是在classpath中使用 Class.getResourceAsStream()键,例如它传递的路径(例如,在应用程序使用的JAR文件) /resource/html/index.html(不要离开了领先的斜线和使用斜线没有反斜杠)。

You can open a file that is on your classpath (e.g. in a jar file used by your application) using Class.getResourceAsStream() and passing it the path e.g. '/resource/html/index.html' (don't leave out the leading slash, and use slash not backslash).

已经打开了的InputStream (也许包裹在一个阅读),你可以从那里复制到的OutputStream HttpServletResponse的(或作家解决这个包裹<$的> C $ C>的OutputStream )。

Having opened that InputStream (perhaps wrapping it in a Reader) you can copy from there to the OutputStream of the HttpServletResponse (or a Writer wrapped around this OutputStream).

原因你可能想打开一个阅读,写的作家是文件的编码(在JAR)是不是你想要送出的HTML编码(例如,作为在响应头设置)。

The reason you might want to open as a Reader and write as Writer is if the encoding of the file (in the jar) is not the encoding you want the HTML sent out as (e.g. as set in the response header).

(这是一种通用的方法,当然,并没有任何做REST或AngularJS。)

(This is a generic approach, of course, and has nothing to do with REST or AngularJS.)

这篇关于请参阅网页中的JAR文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆