「java」スペースを%20に置き換えるサンプルコード

Javaコード
public class Socftdemo {
public String replaceSpace(StringBuffer str) {
for(int j=0;j<str.length();j++)
{
char index=str.charAt(j);
if(index==’ ‘)
{
str.replace(j,j+1,”%20″);
}
}
return str.toString();
}
}

Java.util.PropertyPermission.newPermission Collection() の使い方

Javaコード
package Permission;

import java.security.PermissionCollection;
import java.util.PropertyPermission;

public class NewPermissionDemo {
private static PermissionCollection permissions;

public static void main(String[] args) {
// Build property permissions collection
PropertyPermission permission =
new PropertyPermission(“java.*”, “read”);
permissions = permission.newPermissionCollection();
permissions.add(permission);
permissions.add(new PropertyPermission(“java.changfa.*”, “read,write”));

// Check permissions
checkFileReadPermission(“java.changfa”);
checkFileWritePermission(“java.changfa”);
checkFileReadPermission(“java.changfa.usr”);
checkFileWritePermission(“java.changfa.usr”);
}

private static void checkFileReadPermission(String path) {
// Check permission on read action
if(permissions.implies(new PropertyPermission(path, “read”))) {
System.out.println(“Has permissions on “+path+” 読込み権限”);
}
}

private static void checkFileWritePermission(String path) {
// Check permission on read action
if(permissions.implies(new PropertyPermission(path, “write”))) {
System.out.println(“Has permissions on “+path+” 書込み権限”);
}
}
}

実行結果
Has permissions on java.changfa 読込み権限
Has permissions on java.changfa.usr 読込み権限
Has permissions on java.changfa.usr 書込み権限

「Java」正規表現式でhtmlタグを削除するメモ

サンプルコード

public class StrReplaceDemo {

public static void main(String[] args) {
String str = ” <table border=’1′ cellpadding=’1′ cellspacing=’1′><tr><th rowspan=’2′>都市</th><th colspan=’2′>東京</th><th>大阪</th></tr><table>”;
/**
* html置換
*/
String subStr = str.replaceAll(“\\&[a-zA-Z]{0,9};”, “”).replaceAll(“<[^>]*>”, “\n\t”);
/**
* htmlタグを削除後文字列
*/
System.out.println(“htmlタグを削除後文字列:” + subStr);
}

}

Java.util.PropertyPermission.equals()の使い方

Javaコード
package Permission;

import java.util.PropertyPermission;

public class PermissionEqual {
private static PropertyPermission permission;

public static void main(String[] args) {
// Build property permissions collection
permission = new PropertyPermission(“java.changfa.kdf”, “read”);

// Check file read permissions
checkFileReadPermissions(“java.changfa.kdf”);
// Check file write permissions
checkFileWritePermissions(“java.changfa.kdf”);
}

private static void checkFileReadPermissions(String path) {
// Check permissions are equal
if(permission.equals(new PropertyPermission(path, “read”))) {
System.out.println(“Has permissions on “+path+” 読込み権限”);
}
}
private static void checkFileWritePermissions(String path) {
// Check permissions are equal
if(permission.equals(new PropertyPermission(path, “write”))) {
System.out.println(“Has permissions on “+path+”書込み権限”);
}
}
}

実行結果
Has permissions on java.changfa.kdf 読込み権限

Java.util.PropertyPermission.implies() の使い方

Javaコード
package Permission;

import java.util.PropertyPermission;

public class Impliesdemo {
private static PropertyPermission permission;
public static void main(String[] args) {
// Create property permission object
permission = new PropertyPermission(“java.*”, “read,write”);
// Check permissions
checkFileReadPermission(“java.changfa”);
checkFileWritePermission(“java.changfa”);
}

private static void checkFileReadPermission(String path) {
// Check permission on read action
if(permission.implies(new PropertyPermission(path, “read”))) {
System.out.println(“Has permissions on “+path+” 読込み権限”);
}
}

private static void checkFileWritePermission(String path) {
// Check permission on read action
if(permission.implies(new PropertyPermission(path, “write”))) {
System.out.println(“Has permissions on “+path+” 書込み権限”);
}
}

}

実行結果
Has permissions on java.changfa 読込み権限
Has permissions on java.changfa 書込み権限

「JavaScript」cookieを設定する方法

1.setCookie関数
function setCookie(name, value, days) { //cookie設定
var d = new Date();
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = “expires=” + d.toUTCString();
document.cookie = name + “=” + value + “; ” + expires;
}

2.cookie設定
setCookie(“key”, ‘value’, 1);

3.cookieチェック
document.cookie.indexOf(“key”)

「Java」Java.util.PropertyPermission.hashCode() の使い方

Javaコード
package com.changta.tun;
import java.util.Date;
import java.util.Hashtable;
import java.util.PropertyPermission;

public class HashCodeDemo {
private static Hashtable<PropertyPermission, Date> cft;
@SuppressWarnings(“deprecation”)
public static void main(String[] args) {
// Build property permissions cft collection
cft = new Hashtable<PropertyPermission, Date>();
cft.put(new PropertyPermission(“java.home.chang”, “read”),
new Date(2016, 10, 12));

// Get permissions and cft
checkFilePermissions(“java.home.chang”);
}

private static void checkFilePermissions(String path) {
// Hashcode is calculated by name
PropertyPermission permission = new PropertyPermission(path, “read”);
System.out.println(“Has permissions on “+path+
” for read, Till: “+cft.get(permission));
}

}

実行結果
Has permissions on java.home.chang for read, Till: Sun Nov 12 00:00:00 JST 3916

Java.util.PropertyPermission.getActions() の使い方

Javaコード

package ListResourceBundle;

import java.util.PropertyPermission;

public class ActionsDemo {
private static PropertyPermission permission;

public static void main(String[] args) {
// Build property permissions
permission = new PropertyPermission(“java.changfa.*”, “read,write”);

// Check permissions
checkFilePermissions(“java.changfa.usr”);
}

private static void checkFilePermissions(String path) {
// Check permission given name
if (path.matches(permission.getName())) {
// Get actions list
String actions = permission.getActions();
// Match read write actions
if (actions.contains(“read”))
System.out.println(“message1: ” + path + ” for read”);
if (actions.contains(“write”))
System.out.println(“message2: ” + path + ” for write”);
}
}
}

実行結果
message1: java.changfa.usr for read
message2: java.changfa.usr for write

「shell」メールキューを削除するスクリプト

shellコード
#/bin/bash
#メールファイルパス
quepath=/var/spool/mqueue
#メール件数
filenum=`ls $quepath|wc -l`
#メールを削除
if [ $filenum -ge 100 ];then
find $quepath -type f -name ‘*’ -print0 | xargs -0 rm
rm -rf $quepath/*
fi

Linuxにtomcat7を操作するメモ

インストールディレクトリ
/usr/local/tomcat7

tomcat起動
#cd /usr/local/tomcat7/bin
#./startup.sh

起動プロセス確認
#ps -ef|grep java

tomcatプロセスを停止
#kill -9 2362

再度プロセス確認
#ps -ef|grep java

tomcat再度起動
#./startup.sh

ログ確認
tomcat/logsに入る
#cd ../
#cd logs
#tail -f catalina.out

停止
#ctr+z

tomcatサービスが停止
#cd /usr/local/tomcat7/bin
#./shutdown.sh

ディレクトリの権限を与える
#sudo chmod -R 777 ディレクトリパス