Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!

Jim J Anderson

Ranch Hand
+ Follow
since Jul 15, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
1
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jim J Anderson


Please consider this topic as closed. I may re-post it in the near future, but I think it may be revolved already. My explanation follows.  If reading this, you are probably better off leaving this topic now.

For the curious, I have an unusual set of events in the past 6 hours and my explanation for closing this follows.

Late last night, I wrote up this topic. I thought I hit the 'submit' button (actually, I'm 99.99% sure I did hit the submit button). I woke up early this morning and was anxious to see if anyone had responded. So I got back to my desk and looked at 'my posts'. The most recent thread I found was from last week. I realized that THIS topic had not been posted, so I hit the 'submit' button again and verified that it got posted.

I then reviewed and found a new reply had been posted for the topic that I posted last week. It was excellent guidance for me and I plan to implement the suggestion. I am hopeful that by following the suggestion and restructuring the control of my test website, it will resolve many issues that I have, including the problem documented in this thread.

Had I read the update to last weeks topic first, I never would have posted this thread. My apologies.

If it turns out that the underlying cause is not fixed when I restructure my sample web site, I will then re-open this or more likely, just recreate it.

Jim
5 days ago
JSP

I have been working (and stubbling) on a website for a while. A major problem that I have is to pass data between the server and client. From client to server I often pass data from forms, but when not doing this, I try to use jquery $.ajax() calls. With ajax, I am able to reliably pass date from client to server, but I have not yet settled on a reliable methodology to pass data from the server to the client.

To pass data from the server to client, I have looked at the web page at https://www.programmergate.com/pass-data-servlet-jsp/ and have been working with the first suggested method, "Using request attributes". I put together a simple web page using Apache tomcat as my local server with a simple example with 2 tests. All worked fine. [Note: the full version of the serlvet and the 2 JSP pages are attached. I can make the full example available if necessary.]

In test case 1, the servlet calls: . On the client side, the JSP code is:



Test case 1 works in all cases.

In test case 2, the JSP page has a form. The action for the form is to pass an email address entered in the form to the servlet. The servlet does a getParameter to read the value passed and then saves the value in a javabean. The servlet fetches the java bean value and passes the value by setting a request attribute as follows:



On the client side, the JSP code is:



Test case 2 works in it's original state.

I cleaned up and removed the javascript alert statements that I was using during development. I was surprised to find that when the alert statements were commented out, test case 1 work as expected, but test case 2 failed to pass data from the server to client. I don't understand why this would happen.

Can anyone explain this behavior or suggest what is wrong?

Thanks,

Jim A
5 days ago
JSP
@Bear

Wow! That was quite an article!  Thank you for the pointer.

It is an excellent article to direct me to and I have bookmarked it so I can go back it as needed. I'm not sure I really need to read it again, because I got the underlying message. I have the link, just in case.

I know it will not fix all my problems, but my current 'Model 2' is setup for disaster.

I need some time to restructure my 'sample' websites. Hopefully I can then put together a simple website that works as I expect.

Did I say thank you? Thank you, Thank you, Thank you!

Jim
5 days ago
JSP

First, I thank you all for the comments. My background is largely C/C++ and java application programming, not in website development. JSP is really relatively new to me and I can say I have a lot to learn. I have read several books about JSP, but as yet, I have not really gotten the correct flow and communication down right. In fact, flow is part of my problem - in application programming there are general logical flows that get followed while in website development the asynchronous client/server communication does not really lend itself to that type of thinking. I'm still working a getting a GOOD client/server model, before I burn it into my brain.

Second, the good news is that I resolved the problem by going back to an old working development website that I have and doing some comparisons. I probably made about 5 changes in the code and that fixed the problem. Thus, I will be closing this thread as resolved.
2 weeks ago
JSP

What does "I can no longer get this to work' mean?



I have a website in development. When it was working, I could:

1) bring up the main page
2) fill out a form
3) submit the form
4) pass the form data as a URI to the java HTTPservlet
   [NOTE in this step, a javabean object handle was passed as part
     of an HttpServletRequest object from
      the JSP page to the servlet]
5)  process the URI
6) based on the URI data from the form, the servlet will then
     bring up the appropriate response page

The current behavior is identical until step 4. In step 4 the
    HttpServletRequest object does not have a handle to the
    javabean object, but a 'null' handle. Consequently, the
    servlet fails and passes a null URL to the Tomcat server
    and the server displays a blank screen.

Regarding code, this site is proprietary and I send the source code 'as is'.
I will create a cleansed version and submit it.
2 weeks ago
JSP

I had some code that worked a long while back, but it is not failing. It sucessfully shared a javabean object between a jsp and a servlet. As memory serves me, the JSP created a bean and set a property, e.g.



In the servlet I had code that included this:



I could then cast the object to an 'Info' object (bean) and get or set properties.

I can no longer get this to work.

Can some one recommend a way or point me to a document that explains this.

Thanks. I have already spend a lot of time researching this without success, so
your help is appreciated.

Jim A.
2 weeks ago
JSP

My original post was pretty involved and I closed this issue because, after publishing, I tried playing back what I had described and my description had errors,  It did not illustrate my issue. I was planning to update and open this up again.

The good news is that in putting together a better working example, I discovered the cause of my problem and fixed it.

To keep this short and sweet, my real problem was that my environment CLASSPATH was defined improperly. In my test case, the classpath needed the current directory to be included, e.g.

(A) CLASSPATH = .:/usr/share/example/a.jar

but was set as

(B) CLASSPATH = /usr/share/example/a.jar

Bottom line, if you use:

           javac -d . -classpath $(CLASSPATH)

        then CLASSPATH needs to include the current directory as shown in (A) above.

Pretty basic, but I found it easy to overlook this.

Jim



2 months ago

For some reason, the compiler/translator thinks that JSONObject is a package, not a class.



I thought this was a strange message, which led to my speculation. You are probably correct, but I'm not 100% convinced. I'm also guessing that the error is created during the translation from JSP to java. But again, just a guess.

Why is this code not in a servlet where it would be easier to debug? Putting Java code into a JSP is a bad practice that's been obsolete for over 16 years.



I have been working with JSP on and off for maybe 3 or 4 years now. Mostly experimenting and learning by trial and error. I was using an older text about JSP that has a lot of information and, logically, is probably organized pretty well.  But frankly, it never gave a good explanation on how to develop software using java and JSP. I bought another text a few weeks ago and from a tutorial point of view the new text is better. I would not recommend either text. I have not finished it yet, but I have already seen that writing servlets in java is the direction that I want to move. I could go on and on about how poorly JSP is documented, but I won't.

Anyway, thank you for your comment. It truly reinforces my thoughts about moving to servlets. I had not even thought about servlets making debugging easier. Since I work almost entirely on my own, improved debugging is VERY important to me. I spend far too much time debuggying, not developing. Historically, I'm a C/C++ and java developer and debugging software was never a major problem for me. Debugging in web site development is truly a different ball game. I'm going to start re-writing my examples, including this example, using servlets.

I am going to leave this thread open. Hopefully, after the weekend, I will return to close the issue, or to provide a re-written testcase.

Regards,
Jim
1 year ago
JSP
I am experimenting with JQuery ajax and $.get() methods. I have created a few examples, but the example I am currently working on is giving me an "internal error" message in my browser console window. I am using firefox 61.0.2, Tomcat 8  and jquery-3.3.1.js.

When I run this example, the console log prints out the request URL before giving the "internal error" message. If I enter that URL to my browser, the broswer gives the following error message:

HTTP Status 500 - Unable to compile class for JSP:

type Exception report

message Unable to compile class for JSP:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [14] in the generated java file: [/usr/share/apache-tomcat-8.0.50/work/Catalina/localhost/jjaora/org/apache/jsp/jja_005fexamples/result4_jsp.java]
Only a type can be imported. org.json.simple.JSONObject resolves to a package

An error occurred at line: 8 in the jsp file: /jja_examples/result4.jsp
JSONObject cannot be resolved to a type
5: <%
6:  String name = request.getParameter("name");
7:  String age = request.getParameter("age");
8:     JSONObject json = new JSONObject();



I believe this error is being caused because the jar file json_simple-1.1.jar is not being found. The jar file is being stored in /jjaora/WEB-INF/lib, where /jjaora is the context root for my example website. I have done some reading and my understanding is that if json-simple-1.1.jar is in the .../WEB-INF/lib directory, Tomcat should find and load it.

Assuming that not finding the jar file is my problem, can someone explain how I can coax Tomcat to find the file?

Here is the full result4.jsp file:



1 year ago
I'm sorry to take so long to respond, but that worked. Thank you!!

Is there a may to make this issue as 'resolved'?
1 year ago
I have be looking at this issue on and off for the past day and need some help. This is not a show stopper, just annoying.

I'm developing a web app using tomcat 8.0.50 and Eclipse oxygen. Eclipse is giving me the error message:



I get numerous error messages like the one above and I would like to turn off the caching, or enlarge the cache area to a large enough space that all the caching can be handled.

I looked at https://serverfault.com/questions/644415/tomcat-8-org-apache-catalina-webresources-cache-getresource and added:



to /usr/share/apache-tomcat-8.0.50/conf/context.xml.

Can someone help me with turning off the cache? Or enlarging it to handle the extra caching?
1 year ago

@Norm and Knute

Thanks for your input. As I mentioned, I was experimenting. My intent was to evaluate if there is any performance advantage to using applets vs other styles. The fact that the technology is fading away is a good reason to drop this experiment now. Throw in the security risks and it is even a better reason to stop here.

I will close this issue.

Jim
2 years ago

Hi,

I have been away from java for a few years, but I have been back to it for a few months now. I'm working on putting together a web site and I'm at the point where I'm experimenting with using Java applets in a web page. I spent many hours trying to get my own code working with applets, but no luck there. So, I decided to back up and go to examples that I knew, or at least I thought I knew, would work.

I dug out an example from Core Java Volume 1, edition 8, by Hortsmann and Cornell. The example is from chapter 2 of that book and is called 'WelcomeApplet'. There are 2 files, WelcomeApplet.java and WelcomeApplet.html. I compile the java file first. I then run 'appletviewer Welcome.html'. The html code is not displayed, but the applet comes up and displays as expected, meaning that a window pops up, the title is displayed, and two buttons with labels appear.

When I go to my browser (I tried using firefox and chrome), the applet comes up, but only the html is processed. The applet itself does not get processed. Thus, in the browser, I only see the html, but no buttons from the applet class.

I'm having the same problem with the example that I am having with my own code: I cannot get an applet tag in my html file to be processed by the browsers. I'm baffled and I figure I must be missing something obvious. It appears that when the applet tag is read by the browser, it is not finding the WelcomeApplet.class file, but that is a guess. My understanding is that with the html file and class file in the same directory, the class should be found.

I got the example code doing the following:

1) Go to http://horstmann.com/corejava.html
2) scroll down the page to the "Further Information" section
3) At the 2nd bullet item "Download Code:", click on "8th Edition" and download the zip file
4) unzip the downloaded file
5) change director to the v1ch02/WelcomeApplet directory from the unzipped code
6) The files WelcomeApplet.html and WelcomeApplet.java are there to be viewed

Comments and suggestions are most welcome.

Jim Anderson

2 years ago

User error!

In my script, I referred to my jar file as "Path.jar" and it should have been "Pack.jar", which is the name of the jar file. When I fixed that my test case ran as expected.
2 years ago