copy several files over the same stream
http://www.coderanch.com/t/429978/Sockets-Internet-Protocols/java/Copying-Multiple-Files-Over-Socket#1909216
(澳門)炒家、用家 樓市拉鋸戰
15 年前
linux 下安装jdk6
1、到 sun 网站下载 jdk rpm 软件包 jdk-6u11-linux-i586-rpm.bin;
2、在/usr下建立一个java目录,拷贝 jdk-6u11-linux-i586-rpm.bin 到 java目录;
3、给 jdk-6u11-linux-i586-rpm.bin 加上执行权限,
命令:chmod a+x jdk-6u11-linux-i586-rpm.bin
4、执行: ./jdk-6u11-linux-i586-rpm.bin,得到 jdk-6u11-linux-i586.rpm
5、执行: rmp -ivh jdk-6u11-linux-i586.rpm
6、至此,安装成功,设置环境变量;
7、设置linux的全局环境变量,需要root权限,可在命令行下输入su 切换到root用户;
8、修改etc/profile 文件,在最后加入如下代码:
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
/**
* AD LDAP 登入認證
*
* @param ldap_url like ldap://x.x.x.x:389/DC=mydomain,DC=com
* @param account
* @param password
* @return String[0] array 0 :0 success,1 fail,2 LDAP connect fail,3 unknow
*/
public String[] LDAP_AUTH_AD(String ldap_url, String account, String password) {
String[] returnStr = new String[2];
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldap_url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, account+"@mydomain.com");
env.put(Context.SECURITY_CREDENTIALS, password);
LdapContext ctx = null;
try {
ctx = new InitialLdapContext(env, null);
returnStr[0] = "0";
} catch (javax.naming.AuthenticationException e) {
returnStr[0] = "1";
return returnStr;
} catch (javax.naming.CommunicationException e) {
// System.out.println("Can't connect to ldap server!");
returnStr[0] = "2";
return returnStr;
} catch (Exception e) {
System.out.println("error");
e.printStackTrace();
returnStr[0] = "3";
return returnStr;
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (NamingException e) {
}
}
}
}
package com.demos.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
* Servlet Filter implementation class LoggerFilter
*/
public class LoggerFilter implements Filter {
protected FilterConfig filterConfig = null;
/**
* @see Filter#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
this.filterConfig = null;
}
/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (filterConfig==null)
return;
long bef = System.currentTimeMillis();
ServletContext context = filterConfig.getServletContext();
context.log("in LoggerFilter Class");
// Pass control on to the next filter
chain.doFilter(request, response);
long aft = System.currentTimeMillis();
context.log("Request to " + request.getRemoteHost() + "Total time(ms): " + (aft - bef));
}
/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
this.filterConfig = fConfig;
}
}
loggerFilter
com.demos.filter.LoggerFilter
loggerFilter
/*
/*
action
2009/3/18 下午 6:36:30 org.apache.catalina.core.ApplicationContext log
資訊: in LoggerFilter Class
2009/3/18 下午 6:36:31 org.apache.catalina.core.ApplicationContext log
資訊: Request to 127.0.0.1Total time(ms): 234/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Craig McClanahan
* @version $Revision: 1.2 $ $Date: 2004/03/18 16:40:28 $
*/
package com.demos.filters;
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 SetCharacterEncodingFilter implements Filter {
// ----------------------------------------------------- Instance Variables
/**
* The default character encoding to set for requests that pass through
* this filter.
*/
protected String encoding = null;
/**
* The filter configuration object we are associated with. If this value
* is null, this filter instance is not currently configured.
*/
protected FilterConfig filterConfig = null;
/**
* Should a character encoding specified by the client be ignored?
*/
protected boolean ignore = true;
// --------------------------------------------------------- Public Methods
/**
* Take this filter out of service.
*/
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
/**
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
*
* @param request The servlet request we are processing
* @param result The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
// Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
// Pass control on to the next filter
chain.doFilter(request, response);
}
/**
* Place this filter into service.
*
* @param filterConfig The filter configuration object
*/
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
}
// ------------------------------------------------------ Protected Methods
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}
Set Character Encoding
com.gu.filters.SetCharacterEncodingFilter
encoding
utf-8
ignore
true
Set Character Encoding
action