[Mozile] Java Post Serverside Demo
Lars Kiilerich
mozile at v1p.dk
Mon Jan 16 17:08:35 EST 2006
Hello Everybody.
For those implementing Mozile on a server with Java runtime.
Attached is a small sample of the script i use in my homepage to save
HTTPPosts in Java (JSP).
It might be handy to have in the demo section, along with the PHP
script. James?
/Lars Kiilerich
-------------- next part --------------
<%
// only use POST, any GET's will be hacking attempts :)
if(request.getMethod().equals("POST")){
String result = "";
try {
// read the raw data
ServletInputStream poststrm = request.getInputStream();
// get data from inputstream
int count;
byte[] s = new byte[100];
try {
while ((count = poststrm.readLine(s, 0, 100)) > 0) {
byte[] s2 = new byte[count];
int k;
for (k = 0; k < count; k++) {
s2[k] = s[k];
}
result = result + new String(s2);
}
} catch (java.io.IOException e) {
System.out.print("Exception during processing of raw POST data: ");
e.printStackTrace();
}
} catch (java.io.IOException e) {
System.out.print("Exception during attempt to read http input stream: ");
e.printStackTrace();
}
// change result from UTF-8 to unicode (java native)
// mozile saves in UTF-8 on my homepage, but that is not what my server runs, hence the conversion.
//result = new String(result.getBytes(), "UTF-8");
String mozileID = request.getParameter("MozileID").substring(3); // I use this
// SAVE DATA HERE!
// remember to make ' double for database safety
// result = result.replaceAll("'", "''"); // apostrof
// and check user has rights to save data, so all anonymous users cant edit your pages.
} else {
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="theme/Master.css" rel="stylesheet"
type="text/css" />
<title>Unauthorized</title>
</head>
<body>
Go away!
</body>
</html>
<%
} // end else
%>
More information about the Mozile
mailing list