mdelolmo
mdelolmo

Reputation: 6447

How to call JSP from Servlet wihout affecting the output?

I'm not an expert in Server-side programming nor Java-EE, and I've been looking how to achieve a pretty simple task. I'm not even sure how to express this, which made difficult to google it or to search in the API.

I have one Servlet, This Servlet is calling two different JSP pages. One of them is going to be the actual output, with html code. AFAIU this can be done by this sentence request.getRequestDispatcher("my_jsp_page.jsp").forward(request, response);

But the second JSP I want to call shouldn't be a part of the response/output. It's just a generated vCard (text file). So I think I can't use the previous sentence nor the include method, cause the include would affect the output, am I right?

Any tip or suggestion is greatly appreciated.

Regards.

PD: Probably I didn't express myself correctly. The output of the jsp-html file is displayed on the browser, it's to say, it's the actual response. The output of the jsp-vcard file is a text downloable file, that's why I think it shouldn't be included in the output.

Upvotes: 0

Views: 1267

Answers (3)

Bozho
Bozho

Reputation: 597114

As it seems, the text file has to be generated and stored on the server, and be served in a subsequent request.

Store the file with a normal FileOutputStream, preferably in a location outside the webapp.

Upvotes: 1

Jigar Joshi
Jigar Joshi

Reputation: 240898

You can read text file and set it in response. and set

Content-type: text/plain

Upvotes: 0

James.Xu
James.Xu

Reputation: 8295

As long as the included jsp file dont write anything to the response, you can include it. It will be executed(in your example generate a text file) but will not affect your final output.

Upvotes: 1

Related Questions