Tomcat
March 15, 2009
My Jython Regex Servlet
The servlet:
from javax.servlet.http import HttpServlet
import re
import string
class regexTest(HttpServlet):
def doGet(self,request,response):
self.doPost (request,response)
def doPost(self,request,response):
#param_names = request.getParameterNames()
writer = response.getWriter()
response.setContentType ("text/plain")
try: expr = request.getParameterValues("expr")[0]
except:
final_hash = { "errors" : ['']}
final_hash['errors'][0] = 'You must enter an expression.'
writer.println(final_hash)
sys.exit
try: this_text = request.getParameterValues("text")[0]
except:
final_hash = { "errors" : ['']}
final_hash['errors'][0] = 'You must enter some text.'
writer.println(final_hash)
sys.exit
reg = regexTest()
try: final_hash = reg.test_it(expr, this_text)
except:
final_hash = { "errors" : ['']}
final_hash['errors'][0] = 'Failed to run test.'
writer.println(final_hash)
sys.exit
#except: writer.println('')
#writer.println('')
writer.println(final_hash)
#def __init__(self, text="Stuff"):
# self.text = text
def test_it(self, exp, text):
final_hash = {}
try: this_reg = re.compile(exp)
except:
final_hash['error'] = ['Your expression did not compile']
return final_hash
#print this_reg
this_match = this_reg.findall(text)
final_hash["results"] = this_match
if this_match:
return final_hash
else:
final_hash['error'] = ['Your expression found no matches']
return final_hash
#if __name__ == "__main__":
# reg = regexTest()
# print reg.test_it('[\d]+', 'These are words and phone 07590 574469')
The JSP with the JSON:
<%@ page contentType="text/html" %>
<!-- %@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" % -->
<html>
<head>
<link rel="stylesheet" href="styles.css" type="text/css" media="all"/>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/set_date.js"></script>
<script type="text/javascript">
function do_regex(){
if(($('text').value == '') || ($('regex').value == '')){ alert('You must enter some text and an expression'); return false; }
var url = 'regexTest.py';
var params = '?text=' + escape($('text').value) + '&expr=' + escape($('regex').value);
var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: params,
onComplete: show_response
});
function show_response(this_request){
this_result = this_request.responseText;
$('regex_here').value = this_result;
}
}
</script>
<title>Regular Expression Test Harness</title>
</head>
<body>
<h2 style="margin-left: 1em;">Regex Test Harness</h2>
<form action="#" method="post" style="width: 80%; margin: 2em; border: 1px solid #dcdcdc;">
<p style="margin-left: 1em;">
<label id="text_block_label" class="label_italic">Text
<em class="astrix" id="text_mandatory" style="display: none;">*</em></label>
<br/>
<em id="text_outer">
<input type="text" name="text" id="text" class="four_c" value=""/>
</em>
</p>
<p style="margin-left: 1em;">
<label id="regex_block_label" class="label_italic">Regex
<em class="astrix" id="regex_mandatory" style="display: none;">*</em></label>
<br/>
<em id="regex_outer">
<input type="regex" name="regex" id="regex" class="four_c" value="" onblur="do_regex()"/>
</em> <input type="button" value="Go»" class="button" onclick="do_regex()"/>
</p>
<form>
<textarea style="height: 100px; width: 400px; margin: 1em; color: red;" id="regex_here">
</textarea>
</form>
</form>
</body>
</html>
Posted by pj at 10:01 PM | Comments (0)
February 02, 2009
PHP, MySQL and Tomcat
PHP and MySQL in Tomcat with Quercus � Net Wolf’s Blog
Posted by pj at 02:57 PM | Comments (0)
Using PHP with Tomcat
Posted by pj at 02:54 PM | Comments (0)
May 10, 2006
Running JSP Through Apache with mod_jk2
Running JSP Through Apache with mod_jk2
Posted by pj at 03:40 PM | Comments (0)
March 07, 2006
Getting JSTL EL working on Tomcat 5.0.x
I copied my content into the correct folder but some of my EL expressions weren't working.
This is because I needed namespace declarations in the <web-app/> tag in the web.xml file:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
Posted by pj at 01:55 PM
November 24, 2005
Doing CGI with Windows executables on Tomcat 5
There's a how-to document on the Tomcat site. The interface is managed by a JAR:
http://tomcat.apache.org/tomcat-5.0-doc/cgi-howto.html
The executable parameter needs to be set as follows:
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>clientInputTimeout</param-name>
<param-value>100</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>6</param-value>
</init-param>
<init-param>
<param-name>executable</param-name>
<param-value>cmd /c</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
Posted by pj at 09:27 AM
October 14, 2005
Tomcat Tips
ONJava.com: Top Ten Tomcat Configuration Tips
Posted by pj at 02:14 PM