I'm very new to Java and JSP.
I am working with a purchased Java web application. When I access the application in my browser, there is a file "mysite.com/app/servlet/com.sample.weblet.server.ClientReader?..." that contains a line of Javascript is erroring out in some browsers. I would like to find the source of that Javascript code so that I can modify it so it will be cross-browser compatible.
I've searched all of the JSP and JS files (which are all in a separate folder, and not packaged into JAR files), but could not find the faulty function.
I dug through the JAR files extensively. I only found class declarations, variable declarations, and empty methods. I have not been able to find any logic whatsoever, and definitely have not come across anything resembling javascript auto-generation. There are no WAR files.
I found com.sample.weblet.server.ClientReader in a jar file.. and it just contained a couple of empty methods, yet again.
I am assuming that this faulty JS code is auto-generated. Does that sound correct?
Is there like one main JAR file that has all of the logic? Would it have this JS code hard-coded into it? What am I missing?
Can anyone direct me, or give me any tips?
My suggestion is you should use firebug to detect the javascript error. If any error occurs, you'll see it under "console" tab in firebug and usually there's a link beside it, click on the link will bring you where the bad code resides.
Also, you can navigate javascript files the page has loaded by clicking the list button under "Script" tab in firebug.
Hope it helps.
Related
I wrote http://pastebin.com/EwShF3YS for school; It's a simple java applet with a GUI pair of eyes that watches the cursor as it moves. It runs well in a compiler (NetBeans 7.4) , but for the life of me I'm having difficulty understanding why it doesn't run in a browser. I'm getting ClassNotFound exceptions. All the reading I've been doing suggests that a .class file isn't required because it's an applet, the browser should generate one at runtime. And if a class is required, how come NetBeans can run it without one?
The HTML file is stored in the same directory as the .java - and it's real simple:
<html>
<head>
<title>WatchMe</title>
</head>
<body>
<applet code="WatchMe.class" width="300" height="200">
</applet>
</body>
</html>
I've tried a variety of different things, different browsers, setting classpath; opening it on different computers. The result is always the same, ClassNotFound exception. The internet research I've been doing yields mostly unproductive answers, such as one person who completely reloaded his PC. I've noticed that if I fully qualify the path to WatchMe.class I get a hang/blank browser page. I'm completely out of ideas, so any suggestions or advice is welcome.
You need to have the compiled WatchMe.class in the same directory as HTML File. Having the .java file is not enough and no the browser will not compile anything for you. It will just run the .class file using the JRE.
All the reading I've been doing suggests that a .class file isn't required because it's an applet, the browser should generate one at runtime.
This is incorrect. You must provide either a ".class" file, or JAR files containing ".class" files for the browser to fetch.
A web browser's Java plugin is not capable of compiling Java code. If you've found a resource that tells you otherwise, it is WRONG. (I'd be interested to see concrete examples of this misinformation! Can you post the URLs?)
It is possible that your confusion arises from reading material on Javascript and thinking that it applies to Java. Don't!! They are very different languages ... and material on one does not apply to the other.
OK so why is your example not working?
It is hard to say, but the most likely reasons are:
you've used the wrong name or path in the "code" attribute,
you need a "codebase" attribute to allow the browser to map the ".class" name to the correct URL for downloading it,
your code depends on other classes (that are not in the browser plugin's class library), or
it is a bytecode version issue; i.e. you have compiled your applet with a later version of Java than is supported by the browser.
Try looking in the browser's Java console for the complete error message and stacktrace for the exception.
Try looking at the server-side HTTP logs to see what files that the client is attempting to fetch ... and what the server's response is.
This may be a tricky question because I can't give much detail,
I'm working of legacy code on a big project (in jsp) and I came across a "styleid = product".
It changes quite a lot of things when I remove it, but I can't seem to find it in any of the CSS files, there are properties like "tdproduct" and "thproduct" but I can't seem to find any connection.
Can anyone give me an indication of other places I might need to look for this (except .css files).
thanks in advance
Can you load the page in firefox/chrome browser?
If so you can see the generated source code.
Since JSP is a server side technology that generates some dynamic content, its also possible that the CSS will be also generated dynamically.
Theoretically it can be JSP itself, the CSS and even Java Script :)
Good luck!
Hope this helps
css are dynamically loaded when your page is loaded. your style classes can also be defined in the jsp that you are including in the parent jsp.
open the page in firefox and use firebug to view the styles loaded. You can locate where your style is loading from.
I'm working in another company's code base for a .jsp based site. Most of the site is straight up .jsp pages, but they have a few .java objects those pages use as well. I've modified one of those objects to add an extra function to it, recompiled, and yet the .jsp pages generate a "Method ... not found in class" error when I try calling it.
Obvious things I've already checked out:
It's not a simple typo in the method name.
The method is public.
I'm passing the one String the method signature demands.
The .java file has been recompiled into a .class file that has overstalled the old one.
The object with the new function was already imported and in use.
I have successfully modified other .java objects on this webserver (though not in this exact folder) and seen the changes take effect.
What else might it be?
Generally you have to explicitly set up hot-code replace in Tomcat, and usually it doesn't support adding method signatures - you may have to get the application redeployed and restarted to see the effects properly.
Here's some links for reference information about it:
Link 1
Link 2
Kind of hard to explain in one line but my problem is essentially like this:
I made a java applet that I want to run on a web page that I packaged into a .jar file. I'm able to get the applet working fine using the <applet> tag but the problem is, if the user views the page source, they will see:
<applet archive="directory/program.jar">
Assuming .jar files can be easily opened and all the class files decompiled, all the user would have to do is go to www.url.com/directory/program.jar to download my .jar and they would have all my source code :(
So I'm wondering if there is either a way to protect my code/jar from being decompiled (other than obfuscation) or to use some kind of server-side script to feed the contents of the .jar directly to the browser from a server-side location not publically visible.
Any help is appreciated.
This is fundamentally impossible.
Java applets run the client.
Anything that runs on the client can be disassembled and modified by a sufficiently advanced user.
You should move your sensitive logic to the server and invoke it using HTTP requests ( and remember that the user can use Fiddler).
While you're at it, you should probably replace your applet with HTML and Javascript.
Other than obfuscation or encryption, no--one way or the other, the browser will have access to the jar.
You might be able to create an applet that loads more functionality at runtime.
There is no effective way to block access to the source code of any page; for the page to be readable by browsers and search engines, the source code has to be accessible, and therefore can be viewed and/or copied. That's just how the web works. HTML is sent as a text document and interpreted client-side.
Disabling the right-click is little more than an annoyance, and it works sporadically in alternative browsers. Even if you succeed, the View Source option in the menu is always present. The viewer could also use a download tool such as Wget, or even get the page from the Google cache without visiting your site at all.
Edit: Oops! I misunderstood your question. You should follow #SLaks advice and "move your sensitive logic to the server and invoke ot using HTTP requests ( and remember that the user can use Fiddler)."
While quantum mechanics do rule the universe, they have less of a grip on your code than you might suspect. You cannot both deploy code to the client browser and not deploy code to the client browser. You have the option of doing one or the other.
You can prevent direct browsing to your .jar file by locating it beneath the WEB-INF directory in your WAR file. This will also prevent <applet archive="directory/program.jar"> from working.
Once the jar is beneath the WEB-INF directory you will need something to feed the resource to the client browser; the Spring resources servlet is good for this (If you are using Java and Spring). I feel confident that other such tools exist. With the Sprint resours servlet, your would deploy your applet with something like this: <applet archive="resource/program.jar".
If you write your own resource distributor, you can add security to make it harder to get the jar file; perhaps add a header to your requests like IRGud: <user_id here> and fail any request that does not have that header (or acceptable contents in the header).
In addition to what my title says, I am running into problems because their class file is linked as follows:
"var attributes =
{code:'xx/xxxx/xx/xx/xxx/xxx/xxxxx.class'
width:645,height:443,archive:'xxxxx.jar'}"
First, I naively copied the HTML code and it did show a Java Applet Object, but couldn't load it because it obviously didn't find the class. I tried many different addresses to see if I can download the class, but with no success. Does this mean the class can't be downloaded? I'm in the process of asking for their permission and see if we can get it directly from them.
I also thought of another way. Is it possible to embed their whole page as an iframe AND "crop" it so the iframe only displays the area where the Java Applet is located? If this is possible, it would be the best and easiest way.
You certainly can download the the .jar file - they have to be accessible so that browsers can load them. I'd guess you are trying to get the .class file, but it is within a .jar, so get the .jar instead.