: Code




Send Mail using JMail

July 18th, 2008 admin Posted in ASP Comments Off


<%
Dim objJMail
Dim bSuccess
Dim Recipient
set objJMail = Server.CreateObject("JMail.SMTPMail")
objJMail.Silent = True
objJMail.ServerAddress = "mail.justformspdf.com"
objJMail.ContentType = "text/plain"
objJMail.Sender = "muneebsa@yahoo.com"
Recipient = "muneebsa@yahoo.com"
objJMail.AddRecipient(Recipient)
objJMail.Priority = 3
objJMail.Subject =  "JMail Test"
objJMail.Body = "JMail is perfect"
bSuccess = objJMail.Execute()
If bSuccess = False Then
	Response.Write "An error occurred, the email was not sent." + objJMail.ErrorMessage
Else
	Response.Write "Your message has been sent."
End If
objJMail.Close()
Set objJMail = Nothing
%>
AddThis Social Bookmark Button

Display Files in a Folder

July 18th, 2008 admin Posted in ASP Comments Off

<%@ LANGUAGE="VBSCRIPT" %>
<html>
<head>
<title></title>
<meta NAME="Author" CONTENT="FBRM Development Team">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link REL="stylesheet" HREF="../css/bizapp.css">
<link rel="stylesheet" href="css/fbm_tablesar.css">
</head>
<body BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080" TEXT="#000000" TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" background="./images/tanbg.gif">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
    <td width="142" valign="top" align="left">

    </td>
    <td>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td width="100%">
				<BR><BR>
				<font class="fbm-header01">Document List</font><br>
				<hr NOSHADE>

					<%
					Dim objFSO
					Dim objFolder
					Dim strPath

					strPath = "./lag_files/"
					Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
					Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))

					'For Each objItem In objFolder.SubFolders
					For Each objItem In objFolder.Files

						If InStr(1, objItem, "_vti", 1) = 0 Then
					%>
							<BR>
					<%
						End If
					Next
					%>
			</td>
		</tr>
		</table>
	</td>
<tr valign="top">
      
</tr>
</table>
</body>
</html>
AddThis Social Bookmark Button

Read File Contents

July 18th, 2008 admin Posted in ASP Comments Off


<%@ Language=JavaScript %>

<%
var path = Server.MapPath("file_list_test_3.asp");
var fileSystem = Server.CreateObject("Scripting.FileSystemObject");
var file = fileSystem.OpenTextFile(path);
while (!file.AtEndOfStream) {
Response.Write(Server.HTMLEncode(file.ReadLine()) + "<br>");
}
file.Close();
file = null;
fileSystem = null;

%>
AddThis Social Bookmark Button

Server Variables

July 18th, 2008 admin Posted in ASP Comments Off

<%@ Language=JavaScript %>

<%
PATH_INFO = Request.ServerVariables("PATH_INFO");
LOGON_USER =Request.ServerVariables("LOGON_USER");
REMOTE_ADDR =Request.ServerVariables("REMOTE_ADDR");
LOCAL_ADDR = Request.ServerVariables("LOCAL_ADDR");
REMOTE_HOST =Request.ServerVariables("REMOTE_HOST");
REMOTE_USER =Request.ServerVariables("REMOTE_USER");
REQUEST_METHOD =Request.ServerVariables("REQUEST_METHOD");
SERVER_NAME =Request.ServerVariables("SERVER_NAME");
SERVER_PORT =Request.ServerVariables("SERVER_PORT");
SERVER_PROTOCOL =Request.ServerVariables("SERVER_PROTOCOL");
SERVER_SOFTWARE =Request.ServerVariables("SERVER_SOFTWARE");
URL = Request.ServerVariables("URL");

AUTH_TYPE = Request.ServerVariables("AUTH_TYPE");
AUTH_USER = Request.ServerVariables("AUTH_USER");
AUTH_PASSWORD = Request.ServerVariables("AUTH_PASSWORD");
HTTP_REFERER = Request.ServerVariables("HTTP_REFERER");
HTTP_USER_AGENT = Request.ServerVariables("HTTP_USER_AGENT");
HTTPS = Request.ServerVariables("HTTPS");
CERT_COOKIE = Request.ServerVariables("CERT_COOKIE");

Response.Write("<brServer Variables");
Response.Write("<br>PATH_INFO = " + PATH_INFO);
Response.Write("<br>LOGON_USER = " + LOGON_USER);
Response.Write("<br>REMOTE_ADDR = " + REMOTE_ADDR);
Response.Write("<br>LOCAL_ADDR = " + LOCAL_ADDR);
Response.Write("<br>REMOTE_HOST = " + REMOTE_HOST);
Response.Write("<br>REMOTE_USER = " + REMOTE_USER);
Response.Write("<br>REQUEST_METHOD = " + REQUEST_METHOD);
Response.Write("<br>SERVER_NAME = " + SERVER_NAME);
Response.Write("<br>SERVER_PORT = " + SERVER_PORT);
Response.Write("<br>SERVER_PROTOCOL = " + SERVER_PROTOCOL);
Response.Write("<br>SERVER_SOFTWARE = " + SERVER_SOFTWARE);
Response.Write("<br>URL = " + URL);

Response.Write("<br>AUTH_TYPE = " + AUTH_TYPE);
Response.Write("<br>AUTH_USER = " + AUTH_USER);
Response.Write("<br>AUTH_PASSWORD = " + AUTH_PASSWORD);
Response.Write("<br>HTTP_REFERER = " + HTTP_REFERER);
Response.Write("<br>HTTP_USER_AGENT = " + HTTP_USER_AGENT);
Response.Write("<br>HTTPS = " + HTTPS);
Response.Write("<br>CERT_COOKIE = " + CERT_COOKIE);						

%>
AddThis Social Bookmark Button

TimerFilter : A Simple HTTP Servlet Filter

July 7th, 2008 admin Posted in Java Comments Off


import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class TimerFilter implements Filter {

	public void destroy() {
		System.out.println("destroy");
	}

	public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException {
		System.out.println("doFilter");
		long startTime = System.currentTimeMillis();
		filterChain.doFilter(req, res);
		long stopTime = System.currentTimeMillis();
		System.out.println("took " + (stopTime-startTime) + " milli seconds.");

	}

	public void init(FilterConfig arg0) throws ServletException {
		System.out.println("init");
	}

}

<web-app>

    <filter>
        <filter-name>Timer</filter-name>
        <filter-class>com.msa.filter.TimerFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>Timer</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>    

</web-app>

AddThis Social Bookmark Button

A JSP to Pre-Compile JSPs

July 7th, 2008 admin Posted in Java Comments Off

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.jsp.*"%>
<%@ page import="java.util.Set,java.util.Iterator,java.io.IOException"%>

<%! private void compileAllJsps(PageContext pageContext, JspWriter out, HttpServletRequest request,HttpServletResponse response, String uripath)
         throws IOException, ServletException {

     Set set = pageContext.getServletContext().getResourcePaths(uripath);
     for (Iterator iter = set.iterator(); iter.hasNext();) {
         String uri = (String) iter.next();
         if (uri.endsWith(".jsp")) {
             out.write("<li>"+ uri +"</li>");
             out.flush();
             RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
             if (rd == null) {
                 throw new Error(uri +" - not found");
                 }
             rd.include(request, response);
         }
         else if (uri.endsWith("/")) {
             compileAllJsps(pageContext, out, request, response, uri);
         }
     }
   }
%>

<html>
<head>
<title>Precompiling *.JSPs</title>
</head>
<body>
<h4>Precompiling *.JSPs:</h4>
<ul>
<%
  HttpServletRequest req = new HttpServletRequestWrapper(request) {
  	public String getQueryString() {
          	//return "jsp_precompile";
          	return "jsp_precompile=true";
       };
  };
  compileAllJsps(pageContext, out, req, response, "/");
%>
</ul>
<h4>Done.</h4>
</body>
</html>
AddThis Social Bookmark Button

Object Oriented JavaScript

July 2nd, 2008 admin Posted in Html-JavaScript Comments Off

<script language="JavaScript">
function Person(first, last) {
	this.init(first, last);
}
Person.prototype.init = function(first, last) {
    this.first = first;
    this.last  = last;
};
Person.prototype.toString = function() {
	return this.first + " " + this.last;
}
Employee.prototype = new Person();
Employee.prototype.constructor = Employee;
Employee.superclass = Person.prototype;
function Employee(first, last, id) {
	Employee.superclass.init.call(this, first, last);
	this.id = id;
}
Employee.prototype.toString = function() {
	var name = Employee.superclass.toString.call(this);
	return this.id + ": " +  name;
}
var person = new Person("Muneeb", "Ahmad");
alert(person);
var employee = new Employee("Kevin", "Johnson", 1001);
alert(employee);
</script>
AddThis Social Bookmark Button

Auto Image Refresh

July 2nd, 2008 admin Posted in Html-JavaScript Comments Off

<script language="javascript">
function RefreshImage(){
document.webcam.src="http://yourdomain.com/webcam.jpg?a=" + String(Math.random()*99999999)
setTimeout('RefreshImage()',500);
}
</script>
<body onload="RefreshImage()">
<img name="webcam" src="http://yourdomain.com/webcam.jpg">
</body>
AddThis Social Bookmark Button

A Simple Reflection Example

July 2nd, 2008 admin Posted in Java Comments Off


import java.lang.reflect.Method;
public class SimpleReflection {
	public static void main(String[] args) throws Exception {
		// ================================================
		// The code in this method is equivalent to the following lines of code
		// ————————————————-
		// reflection.Echo echo = new reflection.Echo()
		// String retStr = echo.echo("Muneeb")
		// =================================================

		String className = "reflection.Echo";
		String methodName = "echo";
		Class clazz = Class.forName(className);
		Object obj = clazz.newInstance();

		Class methodParamTypes[] = new Class [1];
		Object methodParamObjects[] = new Object[1];

		methodParamTypes[0] = String.class;
		methodParamObjects[0] = new String("Muneeb");

		Method classMethod = clazz.getMethod(methodName, methodParamTypes);
		Object retObj = classMethod.invoke(obj, methodParamObjects);

		String retStr = (String) retObj;		

		System.out.println("respStr = " + retStr);

	}
}
AddThis Social Bookmark Button

Logon to a Remote Machine and Write File using jCifs

July 2nd, 2008 admin Posted in Java Comments Off

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;

public class Logon {
    public static void main( String argv[] ) throws Exception {
    	String user = "user:password";
        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user);
        String path = "smb://my_machine_name/D/MyDev/test.txt";
        SmbFile sFile = new SmbFile(path, auth);
        SmbFileOutputStream sfos = new SmbFileOutputStream(sFile);
        sfos.write("Muneeb Ahmad".getBytes());
        System.out.println("Done");
    }
}
AddThis Social Bookmark Button

Similar Posts