I am facing a strange problem in apache tomcat.Suppose when I load a class in jsp file it gives me output but when i change the java file recompile changing class file the changes are not shown by apache tomcat,it shows result of previous class...for eg:
<html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
<%# page import="neww.Simpl" %>
<% Simpl demo = new Simpl();
out.println("Current date : " + demo.retur());%>
<%
out.println("Your IP addresssavxcd is " + request.getRemoteAddr());
%>
</body>
</html>
for the first time it shows correct result now if I change the Simpl.java and recompile it and run this jsp file again tomcat gives me previous result.
P.S. I am sure that the class file is modified.
I think that there is something wrong with what you are doing. In particular:
stop tomcat, delete /temp and /work subdirectories' contents, and start it up again.
I tried that already but no help!! I even tried deleting the class file but then to it gives same output.....
If you deleted the old compiled JSP class file, the work and temp directories and restarted the server .... and still saw the old behaviour, then something must be replacing the new version of the JSP source code with the old version. The only plausible explanation for that is that you are modifying the JSP in-place, and a redeploy (from the WAR?) is clobbering your tweaks. But a redeploy shouldn't happen spontaneously. You must be doing something to cause it.
The only other explanation I can think of is that you are deleting the wrong JSP class files, and it is hard to envisage how that might be happening.
Related
My servlet calls a method, which generates a HTML file (different content each time), eg. "[Timestamp].html"
In my jsp I use
<% String time= (String)request.getAttribute("time");
String address= "resources/"+time+".html";
%>
<jsp:include page="<%=address %>"/>
to show the page.
But it gives an error that the requested resource is not available. If I go to [Timestamp].html, it's there.
So, I think my problem is because jsp:include gets the file during compilation, not translation, so the file hasn't been closed yet. Any suggestions for a better strategy for including new content?
Write the generated string directly to a JSP instead of generating a file. So you are saving IO costs and don't have to handle that error.
I have a web-app running on the App Engine Java SDK 1.7.2. The app has no filter and no servlets besides the defaults for serving static content and JSP.
In a JSP file, I have a single line with something like:
<% request.getRequestDispatcher( "a.html" ).include( request, response ); %>
This is throwing a java.lang.IllegalStateException: "getOutputStream has already been called".
If I change the "a.html" for a dynamic content like "a.jsp", everything works fine. The documentation says a RequestDispatcher should work for dynamic and static content.
OBS: I am still learning Servlets and everything related, but I know there are other ways to achieve what I am doing here - this is just an example, not a real world scenario. I just would like to know if this is the expected behaviour and why. Or is it just a bug?
After googling, I learned that this bug has been around for a long time. Look at
http://www.coderanch.com/t/165116/java-Web-Component-SCWCD/certification/RequestDispatcher-include-throws-IllegalStateException
Strange as it might seem, the following works.
<%#page buffer="none"%>
<%
request.getRequestDispatcher("a.html").include(request,response);
%>
Why on earth you are putting scriplets in JSP, it is a horrible way of making your JSP's maintenance nightmare. Anyways looks like your request is already being sent before you are calling this method.
I have a very simple java applet, that Im using source code from the docs.oracle(http://docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html) site that should work, and it works in eclipse just fine, it's getting it onto the page that's the problem. The file is on a localhost server at localhost/applet/applet.html and I have the file JavaQuiz.jar in the same directory. My html file is as follows.
<hmtl>
<applet codebase="localhost/applet/"
code = 'JavaQuiz.jar'
archive = 'JavaQuiz.jar'
width = 300
height = 300 />
</html>
Is there something Im missing? Or need to change? I look forward to any help that could be given, and please try to explain it more than telling me the answer so I can learn. :D
This is what is in the java colsole
Java Plug-in 10.5.1.255
Using JRE version 1.7.0_05-b05 Java HotSpot(TM) Client VM
User home directory = C:\Users\Jihoon
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to
plugin2manager.parentwindowDispose
The Chrome developer help thing doesn't show any problems. And when I click details on the applet it just says classnotfounfexception: JavaQuiz
<html>
<applet
archive="http://localhost/applet/JavaQuiz.jar"
code="JavaQuiz.class"
width = 300
height = 300 />
</html>
I think the biggest problem is not having the http:// I'm not entirely sure about the other parameters. Play around with that.
So in your case change codebase="localhost/applet/" to codebase="http://localhost/applet/"
The code attribute should point to a fully qualified class name, not to a jar.
Also you should have an eye on localhost... this means that the j.jar is located in a folder called localhost in the same directory that the html is in. Is that true? Or do you mean http://localhost:80/applet/ or /applet/
<hmtl> should be <html>
The mandatory "code" attribute (which is missing in your example) should point to the class which you intend to run (the one extending JApplet). Something like:
<html>
<applet codebase="localhost/applet/" code="yourpackage.YourApplet.class"
code = 'JavaQuiz.jar'
archive = 'JavaQuiz.jar'
width = 300
height = 300 />
</html>
http://localhost/applet/JavaQuiz.jar will not work at time of deployment.
<html>
<applet
codebase="."
archive="JavaQuiz.jar"
code="JavaQuiz"
width = 300
height = 300 >
</applet>
</html>
Since the code base points to the 'current directory' this will work for the applet while on localhost as well as deployed live.
Points, some of which have already been mentioned:
The code attribute should be the fully qualified class name of the applet class, without .class on the end.
The applet element cannot be 'self closed' - always use </applet> to close the element.
If omitted the code base defaults to the directory the HTML is in, so putting codebase="." is redundant. It should also work without it.
Hey everyone I am making my first applet for java today. I have been using a subdomain at a server and I don't know what to do because I am getting this really weird error.
I have my jar in the server and everything but every time I try to load the Applet this happens.
java.lang.ClassFormatError: Incompatible magic value 218774561 in class file Evolution/EvolutionApplet
Upon research it appears that an incompatible magic value means that something has been corrupted in the .jar
Here is the website http://dementedgames.site88.net/Main.html
the jars name is Evolution if you need the html code it is at the website.
Edit: The applet should be launched from Evolution.EvolutionApplet not Evolution.Evolution
The magic value of a valid Java class is 0xCAFEBABE, which is the hex value of 3405691582. This is represented by the first 4 bytes of the file. But you're getting 218774561 which in turn stands for the ASCII characters CR, LF, < and ! (the CRLF is a newline). To see it yourself, run this piece of code:
int magic = 218774561;
ByteBuffer b = ByteBuffer.allocate(4);
b.putInt(magic);
System.out.println(new String(b.array()));
This in combination with the applet being served by a website suggests that it's the start of a <!DOCTYPE> which in turn suggests that it's a HTML document.
So, the request to Evolution.jar has apparently actually returned a HTML document. You should be able to see it yourself when you change the current request URI in browser address bar to point to applet's URL (e.g. change /page.html in end of URL to /Evolution.jar). Then you'll see what the browser actually retrieved when it tried to download the applet. Perhaps it's a simple HTTP 404 error document.
To fix it, just make sure that the URL in the archive attribute is correct. It's relative to the current request URL as you see in browser address bar.
The original problem seems fixed now. I could download the Jar from http://dementedgames.site88.net/Evolution.jar
Update
It seems the Evolution.Evolution class is not an applet! Running it from the command line using:
java -jar Evolution.jar
Produces a frame (with a very 'retro' look)! As such, forget this applet nonsense, and launch the frame from a link using Java Web Start.
Old Answer
OTOH it now throws a ClassNotFoundException that (after inspecting the Jar) makes me think it should be:
<html>
<head>
<title>Evolution</title>
</head>
<body bgcolor="#000000" text="#906060">
<center>
<applet code="Evolution.Evolution" archive="Evolution.jar" width="800" height="600">
</applet>
</center>
</body>
</html>
There are two changes to the code attribute worth noting.
The .class extension was removed. A minor matter, adding it is tolerated, but not correct.
The Applet removed from the class name.
BalusC above has explained it really well. In addition to that you can check this link
Thread: Incompatible magic value 218774561 error in applet
It seems that the codebase and/or the code attribute of ur applet tag need to pointed properly.
I'm just starting to learn JSP (and I'm pretty new to Java in general), and I'd like to use JSON-lib with it. I want to make a page something like this:
<%# page import="net.sf.json.JSONObject"%>
<%
String json = new JSONObject().put("hello", "world").toString();
out.println(json);
%>
I downloaded json-lib-2.3-jdk15.jar and put it in the same directory as the .jsp page. But I get this error
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 6 in the generated java file
Only a type can be imported. net.sf.json.JSONObject resolves to a package
An error occurred at line: 3 in the jsp file: /getCard.jsp
JSONObject cannot be resolved to a type
1: <%# page import="net.sf.json.JSONObject" %>
2: <%
3: String json = new JSONObject().put("hello", "world").toString();
4: out.println(json);
5: %>
6:
How do I make the JSONObject class available to my .jsp page?
You need to deploy that jar file with your web application. Usually you have to put it in WEB-INF/lib/ folder.
I ran into a similar problem trying to import net.sf.json.JSONArray and got the same error. But when I replaced "JSONArray" with an asterisk, "*", the error went away. Of course, you need to put the JSON-lib.jar file into your {appdir}/WEB-INF/lib directory. [I still have other associated problems with the JSON-lib being used in my JSP, so I'm not sure my answer is all you need.]