Let me start off by saying that I'm completely new to JSP and servlets. I'm using Eclipse and Tomcat 7. I tried the answer given on this question: JSP page is not getting refreshed after updating, but it still doesn't update.
Here is my jsp file:
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello world</title>
</head>
<body>
<%="Hello World JSP"%>
</body>
</html>
When I run this, the appropriate "Hello World JSP" is output. However if I change the string and run it again, the same old output is displayed. I have to restart Eclipse in order to have the output change, so I'm assuming eclipse is caching the compiled page. Any ideas?
EDIT: The problem has been narrowed down to the Browser cache. The problem only occurs when I use Eclipse's "Internal Web Browser" (Doesn't matter which browser I link that to in preferences). When I run it externally, (through either IE or Firefox), the changes are made.
I'd still like to know however how I can make it so that it updates even using "Internal Web Browser", since it's more convenient.
Check if the broswer is the one caching your page contents even though Tomcat republishes.
Clear your browser's cache to see if this helps.
Also, you can put your browser in a cache-less mode in their options:
Firefox:
Go to Tools menu -> Options -> Advanced tab -> Network subTab and set the value to 0 in the 'Limit cache to #MB of space' field after checking the 'Ignore automatic cache administration' field.
Chrome:
In the Chrome configuration page, go to the Privacy section and click on the 'Content settings' button. In the appearing dialog change the selected option on the Cookies section to any other option that suits your needs.
Eclipse's Internal Web Browser:
Check this question's accepted answer to see how to do it.
Just DELETE your old SERVER(local server like 'Tomcat'). And then again create NEW SERVER.
Just came across this thread. In order to solve this issue, you may need to open up the source code file relating to your JSP page. Make some miniscule change (for instance, add a space, and then remove it) and SAVE the page. Refresh the webpage that you are running locally. The change should be there.
Related
I am working on a jsp web application, There is a jsp page which has datatable that has too many records , but the page loads quickly in chrome or in incognito mode of edge . But when I tried to load it in the normal edge browser It takes lot of time,
Also there is a extension called Microsoft editor If I disable it then the page loads faster. But this is not the actual solution .
I have tried adding
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
in the jsp page. Can someone tell me the reason behind this
Basically I'm running some automated tests using TestNG.
I'm using ITestListener to give real-time results of my tests status but this is outputted to the console.
Is there anyway of outputting the information on the console to a HTML file so I can view the progress from the html file?
I'm planning to create a HTML style report for my own benefit so more specifically would it be possible to place to output to specific parts of the HTML Report I create?
Overall I'm trying to achieve is a HTML file that I can open on Chrome while my tests are running and with an automatic refresh I can view the progress of the tests.
I came up with a solution that uses a small amount of JavaScript to update your browser window:
Your major file would be:
<html>
<head>
<script>
function loadContentFile()
{
document.getElementById("content").innerHTML='<objecttype="type/html" data="content.html"></object>';
}
window.onload = setInterval(loadContentFile, 1000);
</script>
</head>
<body>
<div id="content"></div>
</body>
</html>
Edit:
Your Java program would write to a file called content.html. Just like you have done before. Nothing changes there. The "magic" happens by calling the index.html instead of the content.html. The index.html file when opened with a browser periodically loads the content of the content.html file thus realising a automatic reload of the page.
Conclusion: You have a folder containing the index.html and content.html.
Your browser calls the index.html. Your Java program writes to the content.html.
I've written a Java Applet (in Eclipse, if that makes any difference) and embedded it in a local HTML file (which I will include). The applet code shouldn't be necessary because the problem lies in my HTML. The local HTML file works fine on Chrome, but Chrome is ending support for Java soon, so I'm trying to use the file on Safari. Theoretically, it should all function the same, but the Safari throws a ClassNotFoundException, while Chrome still runs it smoothly. The error reads "ClassNotFoundException", and the detail reads "chaos.chaos.class" (see HTML). (If it's relevant, I'm on OS X 10.10.3, with fully updated everything (I believe)) And, apparently, I'm not allowed to post pictures, so I shall verbally describe the layout of my folders. The HTML file is in the same directory as another directory called 'chaos'. Inside this directory are the 'chaos.jar' and 'chaos.class' referenced in my code, along with 'Shape.class' which is not referenced but is necessary for the applet to run (it's referenced by one to the other files). Thank you in advance for any and all help and suggestions.
UPDATE: I have also tried the HTML file on Firefox, and it works seamlessly there too. But I don't really like Firefox all that much, so I'm still searching for the answer.
<html>
<head>
<title>
The Chaos Game
</title>
</head>
<body align="center">
<blockquote>
<applet code="chaos.chaos.class"
archive="chaos.chaos.jar"
width=900 height=900
title="Chaos">
</applet>
</blockquote>
<br/>
<font size = "3">
Written by ...
</font>
</body>
</html>
This is my JSP file.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
//JFileChooser filechoose = new JFileChooser();
JFileChooser filechoose = new JFileChooser("D:\\");
filechoose.showOpenDialog(null);
File file = filechoose.getSelectedFile();
XLCauHoi.ImportXmlFileToData(file);
%>
<h4> Đã xuất file thành công </h4>
</body>
</html>
My problem is that: the JFileChooser pops up 2 times when I run it on browser. If I run it in a Java class, JFileChooser pops up 1 time.
What is my problem and how to solve it?
There's a major misconception here. First thing, JSP/Java runs at the webserver, produces a bunch of HTML/CSS/JS and sends it to webbrowser. Webbrowser retireves HTML/CSS/JS and interprets/applies/executes it. It doesn't run any line of Java code because it has already been executed on the webserver. Rightclick page in webbrowser and choose View Source. Do you see it? If webserver has done its job right, you should not see any line of Java code in there. The webbrowser namely doesn't understand it. It only understands HTML/CSS/JS.
Using a JFileChooser in a JSP scriptlet would technically only "work" when both the webserver and webbrowser runs at physically the same machine. It's basically the webserver which displays the dialog, not the webbrowser. This would only "work" when you're locally developing, but never when you publish the website into world wide web by a standalone webserver.
To upload files by HTML, you need an <input type="file"> element, not a JFileChooser. For more detail how to use it with JSP/Servlet, check this answer.
As to the concrete problem, I have no idea why it pops 2 times, but that should be your least concern in this particular case.
Is there somehow that I can invoke Java running on a server from a web browser? I would like:
User navigates to URL in a browser
User fills in input boxes (text)
User presses submit button
Input fields are sent as parameters to java that is executing on the server
A new html page is displayed that was generated by the java running on the server.
What is the standard way to do this, or something similar to this.
I think with PHP this would be relatively simple. I think that you would just pass arguments after the URL like this: www.mysite.com/folder?arguments.
Yes, this is possible (and is extremely common). Two of the most common ways are Java Servlets (where responses are generated purely via Java code) and Java Server Pages (where server logic is intermingled within HTML, similar to ASP or PHP).
There are countless ways to serve HTML from Java but virtually all of them rely on java servlets and java server pages (JSPs) which are Java's specification for handling web requests.
The absolute bare minimum to get going:
Install Java EE SDK ensuring to also install Netbeans and Glassfish.
Launch Netbeans and create a "Java Web" / "Web Application" project
Enter a project name, e.g. MyWebApp
In the Server and Settings screen, you need to Add... your server so do so. Point to the file location of your Glassfish server and enter the admin name and password
Ignore the framework stuff and Finish
NetBeans will generate a sample app and you can click straightaway on Run Main Project. It will deploy your app to Glassfish and load http://localhost:8080/MyWebApp/ from your default browser
Important things to note:
A file called web.xml tells the host server some basics about your web app. This file can contain a lot of other stuff but the default is some boiler plate. The most interesting part says <welcome-file>index.jsp</welcome-file> which means when you load http://localhost:8080/MyWebApp/ it will default to load index.jsp.
The index.jsp is what gets loaded if you don't specify a page to the server. If you look at index.jsp it's just HTML with some JSP markup.
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Creating new JSPs is as simple as writing HTML. Netbeans has a wizard to create a simple JSP.
You can embed chunks of Java into a .jsp easily and step in and out of Java / HTML with the <% %> notation such as
<%
for (int i = 0; i < 10; i++) {
%>
Hello <%=i%>
<% } %>
Glassfish is just one possible app server. As long as you write compliant code it should functional with only minimal or zero modifications on any other implementation of Java Servlet / JSP spec. e.g. Jetty, Tomcat, oc4j, JBoss, WebSphere etc.
This is just the tip of the iceberg. You can make things as simple or complex as you like.
Once you know the basics then it's up to you how deep you go. More advanced topics would be:
Taglibraries - these can remove a lot of java clutter and are considered more correct
Expressions - using expressions inside JSP pages to reduce the need for messy <%= notation
Custom servlets let you move model / business stuff into a Java class and leave the .jsp to just presentational
MVC web frameworks like Struts, Spring etc.
Security & filtering
It's a massive subject but it's fairly easy to do something quick and dirty.
As a followup to Mark Peters answer, you need a java web server like Tomcat or GlassFish in order to use servlets or jsps. There are a lot of great frameworks for Java that help you abstract away from the original servlet classes, but I'll let you look those up and decided if you even need them for something this simple.
If you want to pass arguments in a URL, then easier approach is Axis
You can display result with javascript on your page.
If you want to pass arguments in a URL, then easier approach is Axis
My school has an apache server that we are required to use. I was not allowed to install tomcat. I ended up invoking my server side Java using PHP. Not the most beautiful solution but it works.