answersLogoWhite

0


Best Answer

Add the following lines to your JSP: response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", -1); The first line works for HTTP/1.1 clients. The second line works for HTTP/1.0 clients. The third line will tell the browser the content is expired, so if the first two lines don't work, hopefully the third will.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you prevent the output of JSP or Servlet pages from being cached by the browser?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is java servlet chaining?

Servlet Chaining means the output of one servlet act as a input to another servlet. Servlet Aliasing allows us to invoke more than one servlet in sequence when the URL is opened with a common servlet alias. The output from first Servlet is sent as input to other Servlet and so on. The Output from the last Servlet is sent back to the browser. The entire process is called Servlet Chaining.


How do you clear the browser cache in jsp?

Hi to prevent the browser from cache. You have to implement the following code at top of the .jsp page. You will need to set the appropriate HTTP header attributes to prevent the dynamic content output by the JSP page from being cached by the browser. Just execute the following scriptlet at the beginning of your JSP pages to prevent them from being cached at the browser. You need both the statements to take care of some of the older browser versions. <% response.setHeader("Cache-Control","no-cache"); //HTTP 1.1 response.setHeader("Pragma","no-cache"); //HTTP 1.0 response.setDateHeader ("Expires", 0); //prevents caching at the proxy server %>


Is the final output of PHP is in HTML?

Yes. For every web based programming language the final output is browser readable html text


How do you get the image file from the database with JSP?

You can retrieve an image file from a database in JSP by writing a servlet that fetches the image from the database and streams it to the JSP page. The servlet will set the content type to "image/jpeg" or the appropriate image format and write the image data to the response output stream. In the JSP page, you can then display the image by setting the source attribute of the img tag to the servlet URL.


What are java servelets?

When the internet/web was young... there was the webserver. But it didn't do much except fulfill requests for files. Mostly images and .html documents, and such. However, someone noticed that a C program has stdin, stdout and stderr streams... So they made a file extension called .cgi (Common Gateway Interface) and told the webserver that when a request was made to this .cgi file... that it shouldn't SEND a .cgi file to the requestor... instead it should RUN the file as a program, get the program's output and sent THAT output to the browser. Thus web apps were born. Browser Request -> Webserver -> Stdin -> C program... ->>> Stdout -> Webserver -> Response to user's browser. Sun Microsystems wanted to use java for web apps. So, they made tiny classes called "Servlets" (mini-Server programs) to run instead of the C programs/Perl programs everyone else was using. Servlets work like: Browser Request -> Webserver -> Java -> Stdin -> java Servlet Class.. ->>> Stdout -> Webserver -> Response to user's browser. That's pretty much is. A Java Servlet is a program that accepts data, does some processing and then spits out results that a webbrowser would understand. Hope this answers your question.


How do you reduce elctrical harmonics?

You will need to calculate a capacitor at the output stage in order to prevent interaction with the networks connected after the output.


Which one is faster servlet OR jsp?

Servlet is more faster than JSP, but JSP is more convenient than Servlet and JSP is clearly superior, shorter, simple and easier to use. JSP can be perceived as Java in HTML code. JSP require no explicit compilation as like servlets and can keep in the web application server as HTML file. The web application server in turn compile the java code in JSP and load it in its library for future execution. Servlet can be perceived as HTML in Java code. The servlet is the class file, which would be loaded in the web application server as a program. The program output will be directed to the outstream object which in turn direct to the client as HTML elements.


Why are intake and output charts important?

To prevent dehydration or over-hydration


What is the difference between JSP and Servlets?

A JSP is typically oriented more towards displaying information, and a servlet is more oriented towards processing information. For example, a JSP might display a report, while a servlet would process a user submitted form. These uses are not exclusive, but they are optimized more for performing tasks in this manner. It is much easier to incorporate HTML coding into a JSP than a Servlet. It is also easier to write more complex Java code in a servlet.AnswerJSP has Implicit objects and Servlets do not. AnswerJSP and Servlet both define the server end functionality to provide dynamic outputs ,As we know our HTML is only the client end technology version which runs on client browser. JSP and Servlet differ each other in terms of represntation and execution cycle. Servlet are full functional java codes that define the output like write to stream files in protocol defined ways, JSP on the other hand is Role Sepated format to do so where a ordinary web designer designes how will be the presentation of the data and Programmer defines the functinality to provide the underlying things represented in conditional and non conditinal ways , But here is the magic of JSp that merges the both HTML represntation mixed with JAVA scriptlets. Look at http://www.jsptube.com/jsp-tutorials/jsp-introduction.html, it explains how does JSP differs from servlet.


Why are php executables platform independent?

PHP is a server-side language, meaning that the code is executed on the server rather than on the user's local machine. Because of this, it doesn't matter what platform the user is using. In simple terms: User opens their browser -> Browser sends request to server -> Server executes code -> Output is sent back to the browser


Where does PHP used?

PHP is a Server side scripting language used for web development.The programs in php will be run on the server and only the output is sent to the internet browser.


What is the difference between jsp forward and response sendRedirect?

The <jsp:forward ..> is actually a call to HttpServletRequest.forward(String url) which passes the request object within the server to either a servlet or to another JSP page. The new servlet or JSP page continues to process the same request and the browser is not aware of the fact that more than one servlet or page is involved. i.e., The client is not aware that the request is being forwarded somewhere else. The URL shown in the browser stays unchanged when you do this forward. The <jsp:forward> element forwards the request object containing the client request information from one JSP file to another file. The target file can be an HTML file, another JSP file, or a servlet, as long as it is in the same application context as the forwarding JSP file. The lines in the source JSP file after the <jsp:forward> element are not processed. The page invoked by the <jsp:forward> action has access to all the parameters in the original JSP page's request object. You can add new parameters to the request object to pass to the target page by using the <jsp:param name="..." value="..." />. Be careful when using <jsp:forward> with unbuffered output. If the JSP file has any data in the out object, using this forward action will cause an IllegalStateException to be thrown when the page is displayed. The response.sendRedirect() creates a new request object which doesn't carry any of old request information. The first request handler JSP page tells the browser to make a new request to the target servlet or JSP page. The URL shown in the browser therefore changes to the URL of the new page to which you redirect. A redirect is slower than a forward because the browser has to make a new request. Another difference is that request scope objects are no longer available after a redirect because it results in a new request. If you need to pass data to the page you redirect to, you have to use a query string and pass them as request parameters or save the data in the session or application scope objects Forward is faster than redirect but one disadvantage is that URL is not changed and also it works within the same web application. Also, when you choose to use forward, you need to think and confirm what must happen if the user reloads the page.