![]() |
||
![]() |
![]() Alden Hosting provides professional, efficient, and reliable business-class Web hosting and Website Design services. |
|
JAVA, JSP, SERVLETS, TOMCAT, SERVLETS MANAGER, |
•10 Tips for Killer Website Design •7 Sure shots ways to improve your website •Attracting Visitors and Improving Your Search Results •Chasing the Search Engines Algorithms •Crash Course in Getting a 1 Google Ranking •Design Your Site for Traffic in 2005 •Designing A Website That Sells •Googles Good Writing Content Filter •How to Write Effective Web Copy •How to Write Title Tags for Your Web Pages •JSP Scripting Elements and Variables •JSP •Java How to Send Email in Java •Java MySQL Database Connection •Make Money Fast With Google Adwords •Make Money On The Internet What Is Your Niche •Make Money Quick With Google Adsense •Ranked 1 at Google for Invisible Entrepreneurs But No Traffic •Ruby Classes Objects and Variables •Ruby Containers Blocks and Iterators •SEO One Way Web Links 5 Strategies •SEO Success Step Two Attracting Search Engine Attention •The 10 Best Resources for CSS •The 3 Best Website Traffic Sources •The 5 Biggest Mistakes Almost All Web Designers Make •The Five Ways You Should Be Using Keywords •The Three Principles Of Image Optimization •Top 5 Secrets to Making Money with Adsense •True Paid Inclusion Programs are a Thing of the Past •Understanding Web Logs And Why it Matters
|
Web Hosting Tips for Webmasters - |
#!/usr/bin/env ruby print "HTTP/1.0 200 OK\r\n" print "Content-type: text/html\r\n\r\n" print "<html><body>Hello World!</body></html>\r\n" |
CGI
.
CGI
provides support for writing CGI scripts. With it, you
can manipulate forms, cookies, and the environment, maintain stateful
sessions, and so on. It's documented in full in the reference section
beginning on page 497, but we'll take a quick look at its
capabilities here.
%2F
'' and must be translated back
to a ``/'' for you to use it. Space and ampersand are also special
characters. To handle this, CGI
provides the routines
CGI.escape
and CGI.unescape
:
require 'cgi' puts CGI.escape( "Nicholas Payton/Trumpet & Flugel Horn" ) |
Nicholas+Payton%2FTrumpet+%26+Flugel+Horn |
require 'cgi' puts CGI.escapeHTML( '<a href="/mp3">Click Here</a>' ) |
<a href="/mp3">Click Here</a> |
require 'cgi' puts CGI.escapeElement('<hr><a href="/mp3">Click Here</a><br>','A') |
<hr><a href="/mp3">Click Here</a><br> |
A
'' tag is escaped; other tags are left alone.
Each of these methods has an ``un
-'' version to restore the original
string.
CGI
gives you access to HTML query parameters in two
ways.
Suppose we are given a URL of
/cgi-bin/lookup?player=Miles%20Davis&year=1958
. You can access
the parameters ``player
'' and ``year
'' using CGI#[]
directly:
require 'cgi'
|
||
cgi = CGI.new
|
||
cgi['player']
|
» |
["Miles Davis"]
|
cgi['year']
|
» |
["1958"]
|
Hash
:
require 'cgi'
|
||
cgi = CGI.new
|
||
h = cgi.params
|
||
h['player']
|
» |
["Miles Davis"]
|
CGI
contains a huge number of methods used to create HTML---one
method per tag. In order to enable these methods, you must create a
CGI
object by calling CGI.new
, passing in the required level
of HTML. For these examples, we'll use ``html3
''.
To make tag nesting easier, these methods take their content as code
blocks. The code blocks should return a String
, which will be
used as the content for the tag. For this example, we've added some
gratuitous newlines to make the output fit on the page.
require "cgi" cgi = CGI.new("html3") # add HTML generation methods cgi.out{ cgi.html{ cgi.head{ "\n"+cgi.title{"This Is a Test"} } + cgi.body{ "\n"+ cgi.form{"\n"+ cgi.hr + cgi.h1 { "A Form: " } + "\n"+ cgi.textarea("get_text") +"\n"+ cgi.br + cgi.submit } } } } |
Content-Type: text/html Content-Length: 302 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><HEAD> <TITLE>This Is a Test</TITLE></HEAD><BODY> <FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded"> <HR><H1>A Form: </H1> <TEXTAREA NAME="get_text" ROWS="10" COLS="70"></TEXTAREA> <BR><INPUT TYPE="submit"></FORM></BODY></HTML> |
get_text
'' containing the text the
user entered.
CGI#out
.
require "cgi" cookie = CGI::Cookie.new("rubyweb", "CustID=123", "Part=ABC"); cgi = CGI.new("html3") cgi.out( "cookie" => [cookie] ){ cgi.html{ "\nHTML content here" } } |
Content-Type: text/html Content-Length: 86 Set-Cookie: rubyweb=CustID%3D123&Part%3DABC; path= <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML> HTML content here</HTML> |
CustID
and Part
, as shown in the
HTML output.
require "cgi" cgi = CGI.new("html3") cgi.out{ cgi.html{ cgi.pre{ cookie = cgi.cookies["rubyweb"] "\nCookies are\n" + cookie.value.join("\n") } } } |
Content-Type: text/html Content-Length: 111 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><PRE> Cookies are CustID=123 Part=ABC</PRE></HTML> |
CGI::Session
(documented beginning on page 504), which uses cookies
but provides a higher-level abstraction.
require "cgi" require "cgi/session" cgi = CGI.new("html3") sess = CGI::Session.new( cgi, "session_key" => "rubyweb", "session_id" => "9650", "new_session" => true, "prefix" => "web-session.") sess["CustID"] = 123 sess["Part"] = "ABC" cgi.out{ cgi.html{ "\nHTML content here" } } |
$TMP/web-session.9650
with the key, value pairs for CustID
and Part
.
When the user returns, all you need is a parameter to indicate the
session id. In this example, that would be rubyweb=9650
. With
that value in the parameters, you'll be able to retrieve the full
set of saved session data.
require "cgi" require "cgi/session" cgi = CGI.new("html3") sess = CGI::Session.new( cgi, "session_key" => "rubyweb", "prefix" => "web-session.") cgi.out{ cgi.html{ "\nCustomer #{sess['CustID']} orders an #{sess['Part']}" } } |
eruby
and erb
. The remainder of this section will discuss eruby
,
written by Shugo Maeda.
Embedding Ruby in HTML is a very powerful concept---it basically gives
us the equivalent of a tool such as ASP, JSP, or PHP, but with the
full power of Ruby.
eruby
acts as a filter, plain and simple. Any text within the input
file is passed through untouched, with the following exceptions:
Expression | Description | |||||||
<% ruby code %>
|
The Ruby code between the delimiters is replaced with its output. | |||||||
<%= ruby expression %>
|
The Ruby expression between the delimiters is replaced with its value. | |||||||
<%# ruby code %>
|
The Ruby code between the delimiters is ignored (useful for testing). | |||||||
![]() |
eruby
as:
eruby [ options ] [ document ] |
eruby
will read from standard
input. The command-line options for eruby
are shown in Table
14.1 on page 149.
Command-line options for eruby
|
eruby
executable
on the following input.
This text is <% a = 100; puts "#{a}% Live!" %> |
eruby
substitutes the expression between the delimiters and
produces
This text is 100% Live! |
<%a = 100%>This text is almost <%=a%> degrees! Cool! |
=a
with the value of a
.
This text is almost 100 degrees! Cool! |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>eruby example</title> </head> <body> <h1>Enumeration</h1> <ul> <%(1..10).each do|i|%> <li>number <%=i%></li> <%end%> </ul> <h1>Environment variables</h1> <table> <%ENV.keys.sort.each do |key|%> <tr> <th><%=key%></th><td><%=ENV[key]%></td> </tr> <%end%> </table> </body> </html> |
.rhtml
'' suffix
and configure the Web server to run the eruby
executable on these
documents to produce the desired HTML output.
In order to use eruby
with the Apache Web server, you need to
perform the following steps.
eruby
binary to the cgi-bin
directory.
httpd.conf
:
AddType application/x-httpd-eruby .rhtml Action application/x-httpd-eruby /cgi-bin/eruby |
DirectoryIndex
directive such that it includes index.rhtml
. This lets you use
Ruby to create directory listings for directories that do not
contain an index.html
. For instance, the following directive
would cause the embedded Ruby script index.rhtml
to be searched
for and served if neither index.html
nor index.shtml
existed in a
directory.
DirectoryIndex index.html index.shtml index.rhtml |
DirectoryIndex index.html index.shtml /cgi-bin/index.rb |
CGI
library, which is documented
beginning on page 497.
mod_ruby
(available from the archives), an
Apache module that links a full Ruby interpreter into the Apache Web
server itself. The README
file included with mod_ruby
provides
details on how to compile and install it.
Once installed and configured, you can run Ruby scripts just like you
could without mod_ruby
, except that now they will come up much
faster.
Alden Hosting offers private JVM (Java Virtual Machine), Java Server Pages (JSP), Servlets, and Servlets Manager with our Web Hosting Plans WEB 4 PLAN and WEB 5 PLAN , WEB 6 PLAN .
At Alden Hosting we eat and breathe Java! We are the industry leader in providing affordable, quality and efficient Java web hosting in the shared hosting marketplace. All our sites run on our Java hosing platform configured for optimum performance using Java, Tomcat, MySQL, Apache and web application frameworks such as Struts, Hibernate, Cocoon, Ant, etc.
We offer only one type of Java hosting - Private Tomcat. Hosting accounts on the Private Tomcat environment get their very own Tomcat server. You can start and re-start your entire Tomcat server yourself.
![]() |
|
http://alden-servlet-Hosting.com
JSP at alden-servlet-Hosting.com
Servlets at alden-servlet-Hosting.com
Servlet at alden-servlet-Hosting.com
Tomcat at alden-servlet-Hosting.com
MySQL at alden-servlet-Hosting.com
Java at alden-servlet-Hosting.com
sFTP at alden-servlet-Hosting.com
http://alden-tomcat-Hosting.com
JSP at alden-tomcat-Hosting.com
Servlets at alden-tomcat-Hosting.com
Servlet at alden-tomcat-Hosting.com
Tomcat at alden-tomcat-Hosting.com
MySQL at alden-tomcat-Hosting.com
Java at alden-tomcat-Hosting.com
sFTP at alden-tomcat-Hosting.com
http://alden-sftp-Hosting.com
JSP at alden-sftp-Hosting.com
Servlets at alden-sftp-Hosting.com
Servlet at alden-sftp-Hosting.com
Tomcat at alden-sftp-Hosting.com
MySQL at alden-sftp-Hosting.com
Java at alden-sftp-Hosting.com
sFTP at alden-sftp-Hosting.com
http://alden-jsp-Hosting.com
JSP at alden-jsp-Hosting.com
Servlets at alden-jsp-Hosting.com
Servlet at alden-jsp-Hosting.com
Tomcat at alden-jsp-Hosting.com
MySQL at alden-jsp-Hosting.com
Java at alden-jsp-Hosting.com
sFTP at alden-jsp-Hosting.com
http://alden-java-Hosting.com
JSp at alden-java-Hosting.com
Servlets at alden-java-Hosting.com
Servlet at alden-java-Hosting.com
Tomcat at alden-java-Hosting.com
MySQL at alden-java-Hosting.com
Java at alden-java-Hosting.com
sFTP at alden-java-Hosting.com
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP
Servlets
Tomcat
mysql
Java
JSP at JSP.aldenWEBhosting.com
Servlets at servlets.aldenWEBhosting.com
Tomcat at Tomcat.aldenWEBhosting.com
mysql at mysql.aldenWEBhosting.com
Java at Java.aldenWEBhosting.com
Web Hosts Portal
Web Links
Web Links JSP
Web Links servlet
Tomcat Docs
Web Links
Web Links JSP
Web Links servlet
Web Hosting
Tomcat Docs
JSP Solutions Web Links
JSP Solutions Web Hosting
Servlets Solutions Web Links
Servlets Solutions Web Hosting
Web Links
Web Links
.
.
.
.
.
.
.
.
.
.
jsp hosting
servlets hosting
web hosting
web sites designed
cheap web hosting
web site hosting
myspace web hosting