how to make .java and .sql files available for http download

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
I'm such a rookie, learning as I go. I built a webserver database app for the school my kids go to, as a chance to add to my skillset. I figured out how to make it available online, so I can put a link to it in my resume.

I want to make selected source files available, too, as a demo of my coding. I have some java servlets and stored procedures in the database that are way beyond what I was taught in school (fresh out, out there in a tough job market for rookies).

I learned how I can do a simple javascript function that calls

"window.open("http:<IP>:<port>/<webapp><filename>");

and I see it works for .doc and .txt files, but how to do it for .java and .sql files? It looks silly to convert them to .txt and include the instruction to "just change the extension to .java or .sql"

Any help?


 

Argo

Lifer
Apr 8, 2000
10,045
0
0
Assuming you're running apache:

Open mime.conf file and add *.java and *.sql extensions, specifying text/plain for both.
 

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
Well, that was it. I remembered that in the web.xml in Tomcat, there's a huge listing of mime-mappings. There was already one for java

<mime-mapping>
<extension>java</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>

and I added one for

<mime-mapping>
<extension>sql</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>

And it works!! I only vaguely know of the term mime, but the mappings do look clear as to what they do. Great! Thanks!

I wonder why the java didn't work when I first tried? Must have had some typo in my code or something
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
Not too familiar w/ tomcat, I use websphere, but I'd imagine tomcat should just be able to display regular files without any problems.

Alternatively, you should be able to write a simple servlet that'll dump *.java file to response output stream. Just pass the file name to the servlet and then write its content to the output stream. Don't forget to set content type to text/plain.
 

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
Well, now, that makes sense, too. But right now it looks like just getting the files as is, will work. And makes it easy to create a page with a list of files and description of what they do and a button next to each one.

Thanks, though. I didn't think of that but I understand exactly what you mean. There are a lot of servlets in there, and I did the response.getWriter() thing so many times I started to just think in those terms.

It's been a great experience. I would tell anyone -- about the best way to learn is to go get an idea and make yourself build it.
 

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
I'm an intern at a software company, and we also make a webserver, and I'm told it has tomcat at its center, as do others. Tomcat can't do beans, that's the big difference as I understand it. I would have used our own server, but it takes something like 700MB or RAM to work well, and my laptop is a bit short of that
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
I've started my career as MFC/C++ programmer 2 and a half years ago. A year and a half later I switched to J2EE development. To tell you the truth I liked it a lot and I used to hate java back in college. Websphere/J2EE development is a pretty cool thing, although it gets pretty complicated if you start digging deep.

As you correctly mentioned, tomcat can't do beans. In fact, it can't do datasources or lots of other neat things. So it's not a true J2EE environment, but it's probably a good place to start. If you look around there are very few people who know ins and outs of J2EE development, so it's a good career path.