Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!

Tim Holloway

Saloon Keeper
+ Follow
since Jun 25, 2001
Tim likes ...
Android Eclipse IDE Tomcat Server Redhat Java Linux
Long-time moderator for the Tomcat and JavaServer Faces forums. Designer and manager for the enterprise server farm, which runs VMs, a private cloud and a whole raft of Docker containers.
These days, doing a lot of IoT stuff with Arduinos and Raspberry Pi's.
Jacksonville, Florida USA
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tim Holloway

Sorry. I'm exceptionally blind in the mornings. Not used to seeing Java webapps being built one file at a time.

I'm suspecting that the most likely problem is that Agena copied the compile command straight out of the book and that's a problem for two reasons:

1. /your path/tomcat/common/lib/servlet-api.jar - the space between "your" and "path" will throw off the command parser.

2. Almost certainly, Agena has not installed Tomcat in a directory that's literally named "/your path/tomcat". That part needs to be replaced with the actual Tomcat home directory.

Wait, there's a third problem. TOMCAT_HOME/common/lib has not been a valid library path since Tomcat 4. This example is ancient.

The tomcat-api.jar now resides in the TOMCAT_HOME/lib directory.
42 minutes ago
You do not use javac to run servlets. Servlets are not Java Applications.

Servlets are components of Web Applications, which are collections of Servlets, JSPs and supporting resources bundled together in a single deployable unit known as a WAR (for Web Application Archive).

A WAR is not an executable program. It's more like a Windows DLL - a collection of services that can be called. In the case of a Web Application, the caller is a Web Application Server.

So to run a servlet you need to create a WAR and deploy it to a Web Application Server. There are many such servers available, although Tomcat is probably the most popular one for basic applications as it's easy to install, simple to use, and doesn't require a long time to start up and shut down.
1 hour ago
Tomcat has 2 thread pools. One pool services incoming connection requests, one runs the application services (servlets and JSPs).

Tomcat adheres to standard TCP/IP server architecture. It has a Listener for the incoming HTTP port (also for its other ports such as HTTPS, command, and AJP).

When a client sends a request to Tomcat, the Listener dispatches one of the connection threads to handle it. The connection thread is responsible for accepting the request and distilling it into Tomcat internal objects (including the HTTPRequest object). If more connection requests come in than there are connection threads in the pool, the connection request "bounces" and the client is informed that a connection cannot be made. An incoming request may also bounce if the queue of requests received and awaiting processing is full.

Once a request has been distilled and queued internally, the service dispatcher attempts to obtain a Thread for the request service pool. It then passes the request to that thread and initiates the chain of processing calls that ultimately lead into the actual application code itself. Once the application code has finished with the request and returned, the Thread is returned to the request processing pool where it can be handed over to the next waiting request or, if no requests are waiting, the Thread will be placed in the pool's idle queue.
OK. As we said, the standard Java graphics routines do not support having one machine do the graphics and another machine displaying them.

However, there are certainly systems that behave like what you described (including remote whiteboards).

This is generally done by defining a serialized graphics data format - in essence a "program" that the "drawing" machine can send to the "drawn-on" machine. It's the technique used by the X windowing system, by VNC remote access, by the Windows Remote Desktop and many others.

Windows, although not really designed for remote users (or multiple users at all), has a standard for that, which is WMF - the Windows Metafile Format. There's also at least one similar format but I cannot remember its name. Display PostScript is another option, and unlike WMF which is binary and idiosyncratic to Intel byte ordering, PostScript is a text notation. I'm pretty sure that there's at least one XML graphical standard, too.

So in addition to the capture software on the server, you'll need to set up channels for encoding, decoding, and transmission via your socket. Plus, of course, rendering on the client system(s).
13 hours ago
Welcome to the Ranch, Francesca!

We are confused as to what platform your application runs on. Swing, AWT, and SWT are desktop application GUI frameworks and there is no client/server system there. Web applications cannot use Swing, AWT or SWT because those frameworks need to directly control the client computer's graphics hardware and that's not something that the HTTP protocols were ever intended to do. In web applications, any server-side graphics have to be rendered into something in the form of a graphics or video "file" and the data is sent as a unit to the client, which requests it as a sub-URL of a web page request (usually). So we do need more information.
15 hours ago
Welcome to the Ranch, Anhurada!

I think probably that you are using the word "code" wrong.

JSPs are primarily HTML templates designed to present a View to a client. There should not be a lot of executable code in the JSP. That's an obsolete and very hard-to-debug practice. Instead, the JSP should primarily be markdown language (HTML).

However, a popular thing to do these days is to do a partial page update for a client, where instead of replacing the currently-displayed page image (HTML) with a whole new one, you keep the majority of the currently-displayed client-side page and simply update parts of it. And you do that using AJAX.

That's my best guess on what you really want. If you can describe an abstract example of what you are expecting to see happen from the client viewpoint, we can probably offer more specific details.
1 day ago
"Client" is whatever remote application is making requests to the Server. Generally this will be a web browser, but a command-line client application is often used to request web services. For example, I have a client that runs as an OSGi process and once a day, it pulls information from the National Hurricane Center and formats it for me to look at later. I also have weather-sensing equipment that uses short-range radio to a receiver which then posts the observations to a webapp which can display them and keep a history in a database. Another client is a wall-mounted e-paper display device that retrieves and displays some of that information, as well as the daily weather forecast.
4 days ago
Yes, I have had to deal with documents/databases that contained fields with embedded HTML. This was stuff like legal docs and the like where lawyers could never be satisfied with "Is the client dead Y/N?", and felt obliged to put in stuff like "Client is deceased for the purposes of S.R. 237 except when lunar occultation ipso lardo renders in the form of particulate matter as described in Subsection C pending arbitration."

I've also had to take RTF formatted documents and convert them to HTML for web rendering as fields on an HTML page or form.

When at all possible, one should not generate or otherwise render HTML in the Controller code, But sometimes, it's necessary. Ipso Lardo.
4 days ago
It's cheap insurance. I'm pretty sure that most close() methods do invoke flush(), but check the docs for the class in question - and its superclasses. And when in doubt, flush anyway. Double-flushing does no harm.

I once worked with someone who thought that it was OK not to close files because the garbage collector would close them. In actuality (Java 1.4), resources would leak and buffers wouldn't flush. So I've been prone to force the matter myself.

Rob Spoor wrote:Another issue may be SSL certificates. Those may not be available for a wildcard domain, and not every company feels comfortable using Let's Encrypt.

If it's important enough to need an SSL cert and Let'sEncrypt isn't an option, there's no reason for not getting a server cert for a virtualhost. It's not like Apache only supports 1 cert per instance.

Actually, I use LetsEncrypt and I do not have myself set up for wildcard certs. Each of my proxied virtual hosts has its own distinct cert.
4 days ago

fred rosenberger wrote:
as to "Is there a way to optimize the code?"  I would say "Don't".  There's no need to. i'm pretty sure this code would run pretty dang fast.

Not THAT fast! It's making a million passes. It's only fast because modern machines are fast. Certainly Gauss' formula (and thanks for giving the correct version!) is a LOT faster if the range of numbers to be summed exceeds about 20 or so.

I actually got tripped up on this once doing Black-Scholes probability trees. Each individual operation was simple, but there were so many of them. Once I combined the commonalities I got what our finance expert said was the fastest implementation he'd ever seen. And he actually had a proprietary copy as a reference. We just had to re-create it for legal reasons.

On the other hand...

fred rosenberger wrote:Unless you have SPECIFIC and DOCUMENTED timing requirement, you're always better served writing clean, simple code that's easy to understand.  When you go back to it in a week or a month (or in my case, an hour), you don't want to have to struggle to figure out what the heck you did...

4 days ago
Note the "gotcha". If you eliminate 303 because it's a multiple of 3, you also have to have eliminated it from the "sum of 200-399" sub-formula!
4 days ago
I'm going to guess that that last means numbers whose 100's place is 2 or 3, Thus, 200-299, 300-399, 1200-1399, 2200-2399...

You can obviously short circuit 200 additions by subtracting the sum 200...399 from the 1-1,000,000 (excepting multiples of 3) total and do likewise for each of the other blocks. You can probably compact the summing of the other blocks as well, if you're creative.

4 days ago
A famous mathematician whose name I forget was once punished for being too smart for his own good by being assigned the task of adding up all numbers from 1 to 1000 or so. He solved it in minutes by noting that 1+999 = 2+998 = 3.997 ... and thus - if my math is correct - the sum was simply (1000/2) * 1000.

That solution is probably why your own excercise has those extra little qualifications, lest you do likewise. However, I would not be surprised to see a similarly exploitable pattern in this app, since if you apply a rule based on math, there's probably a way to optimise it in math.

I'm not sure what "the numbers whose number of one hundred place is 2 or 3" means in English, though.
4 days ago
Yes you can, but if they are different apps, I wouldn't do it that way. A VirtualHost is easier and simpler.

The only real problem with VirtualHost is if the client runs HTTP version 1.0, which didn't allow multiple hostnames for the same IP address. But that's a protocol that's probably been dead for 15 years.
4 days ago