锘??xml version="1.0" encoding="utf-8" standalone="yes"?> <mailet match="InSpammerBlacklist=dnsbl.njabl.org."
if(l==1|n==1|l==n){
return 1;
}else{
return recursion(l-1,n-1)+recursion(l-1,n);
}
}
public static void main(String[] args){
System.out.println(recursion(7,4));
}
]]>
class="ToProcessor">
<processor> spam </processor>
<notice>550 Requested action not taken: rejected - see http://njabl.org/ </notice>
</mailet>
]]>
((= x 1) 1)
((= x 2) 1)
((= y 1) 1)
((= x y) 1)
(else
(+ (Pascal(- x 1) y) (Pascal (- x 1) (- y 1))
))))
]]>
make install
鎴栨槸涓嶉噸鏂板畨瑁呯殑鎯呭喌涓嬶細
make WITH_PROXY_MODULE=yes
]]>
鎸傝澆錛?br />
mount -t smbfs -o username=administrator,password=pwdabc,iocharset=cpq36 //192.168.0.11/share /mnt/11share
]]>
recursive:
(define (fn n)
(cond ((>= n 3) (+ (+ (fn (- n 1)) (* 2 (fn (- n 2)))) (* 3 (fn (- n 3)))))
((< n 3) n)
))
iterative:
(define (re n)
(if (< n 3)
n
(iter 2 1 0 n)
))
(define (iter a b c n)
(if(= n 3)
(ca a b c)
(iter (ca a b c) a b (- n 1))
)
)
(define (ca a b c)
(+ a (* 2 b) (* 3 c) )
)
(define (new-if predicate then-clause else-clause)
(cond (predicate then-clause)
(else-clause)))
(define (average x y)
(/ (+ x y) 2))
(define (improve guess x)
(average guess (/ x guess)))
(define (good-enough? guess x)
(< (abs (- (square guess) x))0.001))
(define (square x)
(* x x))
(define (sqrt-iter guess x)
(new-if (good-enough? guess x)
guess
(sqrt-iter (improve guess x)
x)))
sqrt-iter (improve guess x)浣滀負鍙傛暟鏉ヤ紶閫掔粰new-if錛屽湪鎵цnew-if鐨勬椂鍊欙紝灝辨繪槸浼氭墽琛宻qrt-iter (improve guess x)錛岄犳垚浜嗘寰幆銆?br />
package com.com;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class ActiveUserListener2 implements HttpSessionListener {
private static int sessionCount2 = 0;
private static Map sessionMaps2 = new HashMap(); //瀛樻斁session鐨勯泦鍚堢被
public void sessionCreated(HttpSessionEvent arg0) {
HttpSession session = arg0.getSession();
String sessionId = session.getId();
System.out.println("Create a session:" + sessionId);
sessionMaps2.put(sessionId, session);
sessionCount2++;
}
public void sessionDestroyed(HttpSessionEvent arg0) {
sessionCount2--;
String sessionId = arg0.getSession().getId();
sessionMaps2.remove(sessionId);//鍒╃敤浼氳瘽ID鏍囩ず鐗瑰畾浼氳瘽
System.out.println("Destroy a session:" + sessionId);
}
public static int getSessionCount() {
return sessionCount2;
}
public static Map getSessionMaps() {
return sessionMaps2;
}
}
浼犻抯essionid錛?jsessionid=<%=session.getId()%>
嫻嬭瘯鏁堟灉錛?br />
<%
Map activeSessions = ActiveUserListener2.getSessionMaps();
out.println(activeSessions.get("CB55ABC39DD5B917D65F456C28FC25E6.tomcat1"));
out.println(activeSessions);
}
}
%>
package client;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.core.client.GWT;
public interface CRUDService extends RemoteService {
Student[] getStudent(String PageNum) ;
String getPagenum();
public static class App {
private static CRUDServiceAsync ourInstance = null;
public static synchronized CRUDServiceAsync getInstance() {
if (ourInstance == null) {
ourInstance = (CRUDServiceAsync) GWT.create(CRUDService.class);
((ServiceDefTarget) ourInstance).setServiceEntryPoint(GWT.getModuleBaseURL() + "CRUD/CRUDService");
}
return ourInstance;
}
}
}
package server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import client.CRUDService;
import client.Student;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.cfg.Configuration;
import java.util.List;
import java.util.Iterator;
public class CRUDServiceImpl extends RemoteServiceServlet implements CRUDService {
private static final SessionFactory sessionFactory;
String Pagenum = "1";
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public List ListStudent(String PageNum){
Session session = getSessionFactory().getCurrentSession() ;
session.beginTransaction();
Query query = session.createSQLQuery("select * from t_student")
.addScalar("id", Hibernate.LONG)
.addScalar("name", Hibernate.STRING)
.addScalar("email", Hibernate.STRING);
int PageSize = 10;
try{
if (Integer.parseInt(PageNum)!=0 | PageNum!=null ){
query.setFirstResult((Integer.parseInt(PageNum)-1) * PageSize);
query.setMaxResults(PageSize);
}else{
query.setFirstResult(0);
query.setMaxResults(PageSize);
}
}catch(Exception e){
query.setFirstResult(0);
query.setMaxResults(PageSize);
}
List ls = query.list();
session.getTransaction().commit();
return ls;
}
public int CountStudent(){
Session session = getSessionFactory().getCurrentSession() ;
session.beginTransaction();
List ls = session.createSQLQuery("select count(*) from t_student").list();
session.getTransaction().commit();
return Integer.parseInt(ls.iterator().next().toString());
}
public Student[] getStudent(String PageNum){
this.setPagenum(PageNum);
Student[] student = new Student[this.CountStudent()];
int i = 0;
for(Iterator it = this.ListStudent(PageNum).iterator();it.hasNext();i++) {
Object[] ob = (Object[] )it.next();
student[i]=new Student(ob[0].toString(),ob[1].toString(),ob[2].toString());
}
return student;
}
public void setPagenum(String pagenum){
this.Pagenum = pagenum;
}
public String getPagenum() {
return Pagenum; //To change body of implemented methods use File | Settings | File Templates.
}
}
package client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface CRUDServiceAsync {
void getStudent(String PageNum, AsyncCallback async);
void getPagenum(AsyncCallback async);
}
package client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.rpc.AsyncCallback;
public class CRUD implements EntryPoint {
private CRUDServiceAsync crudServiceAsync ;
VerticalPanel main = new VerticalPanel();
FlexTable lb = new FlexTable();
HorizontalPanel hp = new HorizontalPanel();
Button nextpage = new Button("nextpage");
Button prepage = new Button("prepage");
private String pagenum = "1";
public void setPagenum(String pagenum){
this.pagenum=pagenum;
}
public String getPagenum(){
return this.pagenum;
}
int prepagenum = 1;
int nextpagenum =1;
public void onModuleLoad() {
main.add(lb);
main.add(hp);
hp.add(prepage);
hp.add(nextpage);
RootPanel.get().add(main);
showstudentlist("1");
prepage.addClickListener(new ClickListener(){
public void onClick (Widget sender){
prepagenum = Integer.parseInt(getPagenum())-1;
showstudentlist(String.valueOf(prepagenum));
}
});
nextpage.addClickListener(new ClickListener(){
public void onClick (Widget sender){
nextpagenum = Integer.parseInt(getPagenum())+1 ;
showstudentlist(String.valueOf(nextpagenum));
}
});
}
private void showstudentlist(String pagenum) {
CRUDService.App.getInstance().getStudent(pagenum,new AsyncCallback(){
public void onFailure(Throwable caught) {
}
public void onSuccess(Object result) {
Student s[] = ( Student[])result ;
for (int i=0;i<=s.length;i++){
lb.setText(i,0,s[i].id);
lb.setText(i,1,s[i].name);
lb.setText(i,2,s[i].email);
}
}
});
CRUDService.App.getInstance().getPagenum(new AsyncCallback(){
public void onFailure(Throwable caught) {}
public void onSuccess(Object result) {
setPagenum((String)result);
}
});
}
}
<module>
<inherits name='com.google.gwt.user.User'/>
<entry-point class='client.CRUD'/>
<servlet path="/CRUD/CRUDService" class="server.CRUDServiceImpl"/>
</module>
EntryPoint錛欳RUD.java錛屼嬌鐢╒erticalPanel 鏉ユ樉紺篖ist錛?/strong>
package client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.rpc.AsyncCallback;
public class CRUD implements EntryPoint {
VerticalPanel main = new VerticalPanel();
FlexTable lb = new FlexTable();
public void onModuleLoad() {
main.add(lb);
RootPanel.get().add(main);
CRUDService.App.getInstance().getStudent(new AsyncCallback(){
public void onFailure(Throwable caught) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void onSuccess(Object result) {
Student s[] = ( Student[])result ;
for (int i=0;i<=s.length;i++){
lb.setText(i,0,s[i].id);
lb.setText(i,1,s[i].name);
lb.setText(i,2,s[i].email);
}
}
}) ;
}
}
ENTITY錛歋tudent.java錛?/strong>
package client;
import com.google.gwt.user.client.rpc.IsSerializable;
public class Student implements IsSerializable {
public String id,name,email;
public Student(){
}
public Student(String id,String name,String email) {
this.id=id;
this.name=name;
this.email=email;
}
}
SERVICE錛欳RUDService.java錛?/strong>
package client;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.core.client.GWT;
public interface CRUDService extends RemoteService {
Student[] getStudent() ;
public static class App {
private static CRUDServiceAsync ourInstance = null;
public static synchronized CRUDServiceAsync getInstance() {
if (ourInstance == null) {
ourInstance = (CRUDServiceAsync) GWT.create(CRUDService.class);
((ServiceDefTarget) ourInstance).setServiceEntryPoint(GWT.getModuleBaseURL() + "CRUD/CRUDService");
}
return ourInstance;
}
}
}
SERVICEImpl錛?/strong>CRUDServiceImpl.java錛岃繖閲屼嬌鐢ㄧ洿鎺ヨ繛鎺ibernate鐨勬柟娉曠敤native sql鏌ヨ鏁版嵁錛屼笉闇瑕佷笓闂ㄥ垱寤哄疄浣撶被鍜岄厤緗枃浠訛細
package server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import client.CRUDService;
import client.Student;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Hibernate;
import org.hibernate.cfg.Configuration;
import java.util.List;
import java.util.Iterator;
public class CRUDServiceImpl extends RemoteServiceServlet implements CRUDService {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public List ListStudent(){
Session session = getSessionFactory().getCurrentSession() ;
session.beginTransaction();
List ls = session.createSQLQuery("select * from t_student")
.addScalar("id", Hibernate.LONG)
.addScalar("name", Hibernate.STRING)
.addScalar("email", Hibernate.STRING).list();
session.getTransaction().commit();
return ls;
}
public int CountStudent(){
Session session = getSessionFactory().getCurrentSession() ;
session.beginTransaction();
List ls = session.createSQLQuery("select count(*) from t_student").list();
session.getTransaction().commit();
return Integer.parseInt(ls.iterator().next().toString());
}
public Student[] getStudent(){
Student[] student = new Student[this.CountStudent()];
int i = 0;
for(Iterator it = this.ListStudent().iterator();it.hasNext();i++) {
Object[] ob = (Object[] )it.next();
student[i]=new Student(ob[0].toString(),ob[1].toString(),ob[2].toString());
}
return student;
}
}
寮傛璋冪敤綾籆RUDServiceAsync.java錛?/strong>
package client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface CRUDServiceAsync {
void getStudent(AsyncCallback async);
}
鏈鍚庯紝鍦╯rc鐩綍涓嬪垱寤篽ibernate.cfg.xml錛岃繖閲屼嬌鐢╩ysql錛?/strong>
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/mysql
</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">
org.hibernate.cache.NoCacheProvider
</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="myeclipse.connection.profile">mysql for j</property>
</session-factory>
</hibernate-configuration>
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link href="<%=request.getContextPath() %>/admin/uploadpic/js/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/admin/uploadpic/js/swfupload.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/admin/uploadpic/js/handlers.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/admin/uploadpic/js/fileprogress.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/admin/uploadpic/js/swfupload.queue.js"></script>
<script type="text/javascript">
var swfu;
window.onload = function () {
var settings = {
// Backend Settings
file_post_name : "upload",
upload_url: "<%=request.getContextPath() %>/admin/product/doMultipleUploadUsingList.action", // Relative to the SWF file
post_params: {"product1": "1"},
use_query_string:false,
// File Upload Settings
file_size_limit : "100 MB",
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel"
},
debug: false,
// The event handler functions are defined in handlers.js
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete,
// Flash Settings
flash_url : "<%=request.getContextPath() %>/admin/uploadpic/js/swfupload_f8.swf" // Relative to this file
};
swfu = new SWFUpload(settings);
}
function uploadStart(file) {
document.getElementById("back").innerHTML='';
var post_params = this.settings.post_params;
post_params.id = document.getElementById("id").value;
this.setPostParams(post_params);
return true;
}
<style type="text/css">
#content button,input,span{
margin: 5 5 5 5;
}
#back{
width:810;
height:500;
float:left;
text-align:center;
vertical-align:middle;
overflow:auto;
}
#img2{
float:left;
margin: 1 1 1 1;
text-align:center;
vertical-align:middle;
display: table-cell;
display: block;
font-size: 68px;
width:78;
height:78;
border: 1px solid #B10000;
}
#img2 img{
vertical-align:middle;
cursor: pointer;
}
#img2 img hover{
cursor: pointer;
}
</style>
</head>
<div id="SWFUploadTarget" >
<body>
<div id="content">
<span>1銆丳roduct ID</span><input type="text" name="id" id="id" value= <%=request.getParameter("id") %> readonly>
<button id="btnBrowse" type="button" style="padding: 6px;" onClick="swfu.selectFiles(); this.blur();javascript:document.getElementById('divStatus').innerHTML='';">
</div>
</div>
<p>
<fieldset class="flash" id="fsUploadProgress">
<legend>Upload Progress</legend>
</fieldset>
<div id="divStatus"></div>
<div>
<input id="btnCancel" type="button" value="Cancel All Upload" onClick="swfu.cancelQueue();" disabled="disabled" style="font-size: 8pt;" />
</div>
<div id="back"></div>
</body>
<html>
MultipleFileUploadUsingListAction鏄竴涓彲浠ラ氱敤鐨剆truts2 action錛屽彲浠ユ帴鏀舵壒閲忔垨鍗曚釜涓婁紶榪囨潵鐨勫浘鐗囥傚茍涓斿彲浠ラ夋嫨鐢熸垚鐩稿簲鍘嬬緝鍥俱傚浘鐗囩敓鎴愮殑鍛藉悕鏂瑰紡鏄粠xxx_01銆亁xx_02銆亁xx_03涓鐩磋嚜鍔ㄦ帓鍒椾笅鍘匯傚帇緙╁浘涓簒xx_01_70
package com..web.action;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.web.commons.util.DirList;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
@SuppressWarnings("serial")
public class MultipleFileUploadUsingListAction extends ActionSupport {
private String id;
private File[] uploads;
private String[] uploadFileNames;
private String[] uploadContentTypes;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public File[] getUpload() { return this.uploads; }
public void setUpload(File[] upload) { this.uploads = upload; }
public String[] getUploadFileName() { return this.uploadFileNames; }
public void setUploadFileName(String[] uploadFileName) { this.uploadFileNames = uploadFileName; }
public String[] getUploadContentType() { return this.uploadContentTypes; }
public void setUploadContentType(String[] uploadContentType) { this.uploadContentTypes = uploadContentType; }
public String upload() throws Exception{
try{
String productname=id;
String url = ServletActionContext.getServletContext().getRealPath("Personalizedphoto")+"\\"+id+"\\";
for (int i=0;i<uploads.length;i++) {
FileInputStream fis=new FileInputStream(uploads[i]);
if(!(new File(url).isDirectory()))
{
new File(url).mkdir();
}
int temp=1,temp2=1;
String myFileName = productname+"_0"+temp;
DirList dirlist = new DirList();
String[] dir =dirlist.list(url);
for(int j=0;j<dir.length;j++){
String[] split = dir[j].split("\\.");
if(split[1].equals("jpg")&&split[0].split("\\_").length==3){
String[] split2=split[0].split("\\_");
if(Integer.parseInt(split2[1])>0&Integer.parseInt(split2[1])>=temp2){
temp2=Integer.parseInt(split2[1])+1;
}
if(Integer.parseInt(split2[1])==0){
temp2=1;
}
}
}
if(temp2<10){
myFileName = productname+"_0"+temp2;
}else{
myFileName = productname+"_"+temp2;
}
FileOutputStream fos=new FileOutputStream(url+myFileName+"_800.jpg");
byte[] buffer=new byte[1024];
int len=0;
while((len=fis.read(buffer))>0){
fos.write(buffer, 0, len);
}
java.io.File file = new java.io.File(url+myFileName+"_800.jpg");
String newurl=url+myFileName+"_70.jpg";
java.awt.Image src = javax.imageio.ImageIO.read(new java.io.File(url+myFileName+"_800.jpg"));
float tagsize=70;
int old_w=src.getWidth(null);
int old_h=src.getHeight(null);
int new_w=0;
int new_h=0;
float tempdouble;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble); java.awt.image.BufferedImage tag = new java.awt.image.BufferedImage(new_w,new_h,java.awt.image.BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null);
FileOutputStream newimage=new FileOutputStream(newurl);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag);
newurl=url+myFileName+"_130.jpg";
tagsize=130;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);
tag = new java.awt.image.BufferedImage(new_w,new_h,java.awt.image.BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null);
newimage=new FileOutputStream(newurl);
encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag);
newurl=url+myFileName+"_180.jpg";
tagsize=180;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);
tag = new java.awt.image.BufferedImage(new_w,new_h,java.awt.image.BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null);
newimage=new FileOutputStream(newurl);
encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag);
newurl=url+myFileName+"_500.jpg";
tagsize=500;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);
tag = new java.awt.image.BufferedImage(new_w,new_h,java.awt.image.BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null);
newimage=new FileOutputStream(newurl);
encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag);
newimage.close();
}
}catch(Exception e){}
this.setId(id);
return SUCCESS;
}
}
榪欎釜action榪樿皟鐢ㄤ簡涓涓被DirList 錛屾槸鐢ㄤ簬鎵弿褰撳墠鏂囦歡澶歸噷鐨勫浘鐗囷紝騫朵笖鏍規嵁褰撳墠鐨勫懡鍚嶆儏鍐墊潵鍛藉悕鏂頒笂浼犵殑鍥劇墖錛屽鍘熸潵宸茬粡鏈変簡10寮狅紝閭d笂浼犱箣鍚庣殑灝變粠絎?1寮濮嬪懡鍚嶃?br />
import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.regex.Pattern;
public class DirList {
public String[] list(String thepath) {
File path = new File(thepath);
String[] list;
list = path.list();
Arrays.sort(list, new AlphabeticComparator());
return list;
}
private void deleteFile(File file){
if(file.exists()){
if(file.isFile()){
file.delete();
}else if(file.isDirectory()){
File files[] = file.listFiles();
for(int i=0;i<files.length;i++){
this.deleteFile(files[i]);
}
}
file.delete();
}else{
}
}
}
class DirFilter implements FilenameFilter {
private Pattern pattern; public DirFilter(String regex) {
pattern = Pattern.compile(regex); }
public boolean accept(File dir, String name) {
// Strip path information, search for regex:
return pattern.matcher(new File(name).getName()).matches();
}
}
class AlphabeticComparator implements Comparator {
public int compare(Object o1, Object o2) {
String s1 = (String) o1; String s2 = (String) o2;
return s1.toLowerCase().compareTo(s2.toLowerCase());
}
}
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="com.yourcompany.util.*"%>
<html>
<head>
<link href="js/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/swfupload.js"></script>
<script type="text/javascript" src="js/handlers.js"></script>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javacript">
function g(){
$.ajax({
url: 'upload2.jsp',
date: {c: $('#c').val(), c: $('#c').val()},
error: function() { alert"fail"},
success: function(response) { ... }
});
}
</script>
<script type="text/javascript">
var swfu;
window.onload = function () {
swfu = new SWFUpload({
// Backend Settings
upload_url: "upload2.jsp", // Relative to the SWF file
post_params: {"product1": "1"},
use_query_string:false,
// File Upload Settings
file_size_limit : "2048", // 2MB
file_types : "*.jpg",
file_types_description : "JPG Images",
file_upload_limit : "0",
// Event Handler Settings - these functions as defined in Handlers.js
// The handlers are not part of SWFUpload but are part of my website and control how
// my website reacts to the SWFUpload events.
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_progress_handler : uploadProgress,
upload_start_handler : uploadStart,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
// Flash Settings
flash_url : "js/swfupload_f9.swf", // Relative to this file
custom_settings : {
upload_target : "divFileProgressContainer"
},
// Debug Settings
debug: false
});
}
function uploadStart(file) {
var post_params = this.settings.post_params;
post_params.product = document.getElementById("product").value;
this.setPostParams(post_params);
return true;
}
</script>
</head>
<div id="SWFUploadTarget">
<body>
<div>
<form action="upload2.jsp" method="get">
<button id="btnBrowse" type="button" style="padding: 5px;" onClick="swfu.selectFiles(); this.blur();"><img src="images/page_white_add.png" style="padding-right: 3px; vertical-align: bottom;">璇烽夋嫨鍥劇墖<span style="font-size: 7pt;">(2 MB Max)</span></button>
璇瘋緭鍏ヤ駭鍝両D<input type="text" name="product" id="product" value="">
</form>
</div>
<div id="divFileProgressContainer" style="height: 75px;"></div>
<div id="thumbnails"></div>
</div>
</body>
<html>
鍚庡彴浣跨敤SmartUpload錛?br />
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*,
java.sql.*,com.jspsmart.upload.*,java.util.*,com.yourcompany.util.*"%>
<%
SmartUpload mySmartUpload =new SmartUpload();
long file_size_max=4000000;
//add
//鍒濆鍖?br />
mySmartUpload.initialize(pageContext);
//鍙厑璁鎬笂杞芥綾繪枃浠?br />
try {
mySmartUpload.setAllowedFilesList("jpg,gif");
//涓婅澆鏂囦歡
mySmartUpload.upload();
} catch (Exception e){
%>
<SCRIPT language=javascript>
alert("鍙厑璁鎬笂浼?jpg鍜?gif綾誨瀷鍥劇墖鏂囦歡");
window.location=''upfile.jsp'';
</script>
<%
}
//try{
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
if (myFile.isMissing()){%>
<SCRIPT language=javascript>
alert("璇峰厛閫夋嫨瑕佷笂浼犵殑鏂囦歡");
window.location=''upfile.jsp'';
</script>
<%}
else{
String fileName2="",ext="",testvar="";
String productname=mySmartUpload.getRequest().getParameter("product");
String url="/uploadfile/"+productname+"/"; //搴斾繚璇佸湪鏍圭洰褰曚腑鏈夋鐩綍鐨勫瓨鍦?/p>
java.io.File file1 = new java.io.File(request.getRealPath("/") + url );
if(!file1.exists())
{
file1.mkdir();
}
//String myFileName=myFile.getFileName(); //鍙栧緱涓婅澆鐨勬枃浠剁殑鏂囦歡鍚?br />
ext= myFile.getFileExt(); //鍙栧緱鍚庣紑鍚?br />
int file_size=myFile.getSize(); //鍙栧緱鏂囦歡鐨勫ぇ灝?nbsp;
String saveurl="";
if(file_size<file_size_max){
int temp=1,temp2=0;
String[] a=myFile.getFileName().split(".jpg");
String myFileNameo = productname+"_00_pic_big";
String myFileName = productname+"_0"+temp;
Calendar calendar = Calendar.getInstance();
String filename = String.valueOf(calendar.getTimeInMillis());
saveurl=request.getRealPath("/")+url;
saveurl+=myFileNameo+"."+ext; //淇濆瓨璺緞
myFile.saveAs(saveurl,mySmartUpload.SAVE_PHYSICAL);
// java.io.File f1 = new java.io.File (saveurl);
// java.io.File f2 = new java.io.File (request.getRealPath("/")+url+myFileName+"_0_big.jpg");
// f1.renameTo(f2);
//out.print(filename);
//-----------------------涓婁紶瀹屾垚錛屽紑濮嬬敓鎴愮緝鐣ュ浘-------------------------
com.yourcompany.util.DirList dirlist = new com.pixel.util.DirList();
String[] dir =dirlist.list(request.getRealPath("/") + url );
for(int i=0;i<dir.length;i++){
//for (String i : dir){
String[] split = dir[i].split("\\.");
if(split[1].equals("jpg")){
String[] split2=split[0].split("\\_");
//split2[1]=01
if(Integer.parseInt(split2[1])>0&Integer.parseInt(split2[1])>=temp2){
temp2=Integer.parseInt(split2[1])+1;
}
if(Integer.parseInt(split2[1])==0){
temp2=1;
}
}
}
if(temp2<=10){
myFileName = productname+"_0"+temp2;
}else{
myFileName = productname+"_"+temp2;
}
//myFileName = mySmartUpload.getRequest().getParameter("product");
java.io.File file = new java.io.File(saveurl); //璇誨叆鍒氭墠涓婁紶鐨勬枃浠?br />
String newurl=request.getRealPath("/")+url+myFileName+"_70_min."+ext; //鏂扮殑緙╃暐鍥句繚瀛樺湴鍧
Image src = javax.imageio.ImageIO.read(file); //鏋勯營mage瀵硅薄
float tagsize=70;
int old_w=src.getWidth(null); //寰楀埌婧愬浘瀹?br />
int old_h=src.getHeight(null);
int new_w=0;
int new_h=0; //寰楀埌婧愬浘闀?br />
int tempsize;
float tempdouble;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);//璁$畻鏂板浘闀垮
BufferedImage tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null); //緇樺埗緙╁皬鍚庣殑鍥?br />
FileOutputStream newimage=new FileOutputStream(newurl); //杈撳嚭鍒版枃浠舵祦
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag); //榪慗PEG緙栫爜
//璇誨叆鍒氭墠涓婁紶鐨勬枃浠?br />
newurl=request.getRealPath("/")+url+myFileName+"_130_min."+ext; //鏂扮殑緙╃暐鍥句繚瀛樺湴鍧
//Image src = javax.imageio.ImageIO.read(file); //鏋勯營mage瀵硅薄
tagsize=130;
// int old_w2=src2.getWidth(null); //寰楀埌婧愬浘瀹?br />
// int old_h2=src2.getHeight(null);
// int new_w=0;
// int new_h=0; //寰楀埌婧愬浘闀?br />
// int tempsize;
// float tempdouble;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);//璁$畻鏂板浘闀垮
tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null); //緇樺埗緙╁皬鍚庣殑鍥?br />
newimage=new FileOutputStream(newurl); //杈撳嚭鍒版枃浠舵祦
encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag); //榪慗PEG緙栫爜
newurl=request.getRealPath("/")+url+myFileName+"_180_min."+ext; //鏂扮殑緙╃暐鍥句繚瀛樺湴鍧
//Image src = javax.imageio.ImageIO.read(file); //鏋勯營mage瀵硅薄
tagsize=180;
// int old_w2=src2.getWidth(null); //寰楀埌婧愬浘瀹?br />
// int old_h2=src2.getHeight(null);
// int new_w=0;
// int new_h=0; //寰楀埌婧愬浘闀?br />
// int tempsize;
// float tempdouble;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);//璁$畻鏂板浘闀垮
tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null); //緇樺埗緙╁皬鍚庣殑鍥?br />
newimage=new FileOutputStream(newurl); //杈撳嚭鍒版枃浠舵祦
encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag); //榪慗PEG緙栫爜
newurl=request.getRealPath("/")+url+myFileName+"_500_min."+ext; //鏂扮殑緙╃暐鍥句繚瀛樺湴鍧
//Image src = javax.imageio.ImageIO.read(file); //鏋勯營mage瀵硅薄
tagsize=500;
// int old_w2=src2.getWidth(null); //寰楀埌婧愬浘瀹?br />
// int old_h2=src2.getHeight(null);
// int new_w=0;
// int new_h=0; //寰楀埌婧愬浘闀?br />
// int tempsize;
// float tempdouble;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);//璁$畻鏂板浘闀垮
tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null); //緇樺埗緙╁皬鍚庣殑鍥?br />
newimage=new FileOutputStream(newurl); //杈撳嚭鍒版枃浠舵祦
encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag); //榪慗PEG緙栫爜
newurl=request.getRealPath("/")+url+myFileName+"_800_min."+ext; //鏂扮殑緙╃暐鍥句繚瀛樺湴鍧
//Image src = javax.imageio.ImageIO.read(file); //鏋勯營mage瀵硅薄
tagsize=800;
// int old_w2=src2.getWidth(null); //寰楀埌婧愬浘瀹?br />
// int old_h2=src2.getHeight(null);
// int new_w=0;
// int new_h=0; //寰楀埌婧愬浘闀?br />
// int tempsize;
// float tempdouble;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);//璁$畻鏂板浘闀垮
tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null); //緇樺埗緙╁皬鍚庣殑鍥?br />
newimage=new FileOutputStream(newurl); //杈撳嚭鍒版枃浠舵祦
encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag); //榪慗PEG緙栫爜
newimage.close();
}
else{
out.print("<SCRIPT language=''javascript''>");
out.print("alert(''涓婁紶鏂囦歡澶у皬涓嶈兘瓚呰繃"+(file_size_max/1000)+"K'');");
out.print("window.location=''upfile.jsp;''");
out.print("</SCRIPT>");
}
}
//}catch (Exception e){
//e.toString();
//}
%>
for(int i=0;i<dir.length;i++){
//for (String i : dir){
String[] split = dir[i].split("\\.");
if(split[1].equals("jpg")){
String[] split2=split[0].split("\\_");
//split2[1]=01
if(Integer.parseInt(split2[1])>0&Integer.parseInt(split2[1])>=temp2){
temp2=Integer.parseInt(split2[1])+1;
}
if(Integer.parseInt(split2[1])==0){
temp2=1;
}
}
}
if(temp2<=10){
myFileName = productname+"_0"+temp2;
}else{
myFileName = productname+"_"+temp2;
}
import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.regex.Pattern;
public class DirList {
public String[] list(String thepath) {
File path = new File(thepath);
String[] list;
list = path.list();
Arrays.sort(list, new AlphabeticComparator());
return list;
}
}
class DirFilter implements FilenameFilter {
private Pattern pattern; public DirFilter(String regex) {
pattern = Pattern.compile(regex); }
public boolean accept(File dir, String name) {
// Strip path information, search for regex:
return pattern.matcher(new File(name).getName()).matches();
}
}
class AlphabeticComparator implements Comparator {
public int compare(Object o1, Object o2) {
String s1 = (String) o1; String s2 = (String) o2;
return s1.toLowerCase().compareTo(s2.toLowerCase());
}
}
NodeList childNodes = fatherNode.getChildNodes();
System.out.println(childNodes.getLength());
for(int j=0;j<2;j++){
Node childNode=childNodes.item(j);
//濡傛灉榪欎釜鑺傜偣灞炰簬Element ,鍐嶈繘琛屽彇鍊?br />
if(childNode instanceof Element){
//System.out.println("瀛愯妭鐐瑰悕涓?"+childNode.getNodeName()+"鐩稿搴旂殑鍊間負"+childNode.getFirstChild().getNodeValue());
System.out.println("瀛愯妭鐐瑰悕涓?"+childNode.getNodeName()+"鐩稿搴旂殑鍊間負"+childNode.getFirstChild().getNodeValue());
}
}
}
public static void main(String[] args)throws Exception{
Parse parse=new Parse();
//鎴戠殑XML鏂囦歡
parse.viewXML("D:/Tomcat 5.5/webapps/ROOT/story/best_story.xml");
}
}
LoadModule jk_module modules/mod_jk.so
JkWorkersFile "C:\Program Files/Apache Software Foundation/Apache2.2/conf/workers.properties"
JkLogFile "C:\Program Files/Apache Software Foundation/Apache2.2/logs/mod_jk.log"
JkLogLevel severe
JkMount /*.do controller
JkMount /*.jsp controller
JkMount /WEB-INF/* controller
JkMount /lzj1/*.do controller
worker.tomcat1.host=192.168.10.55
worker.tomcat1.port=8009
worker.tomcat2.port=8009
worker.tomcat2.host=localhostworker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2
worker.controller.sticky_session=1
worker.ajp13.lbfactor=1
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
/*<%
System.out.println("===========================");
%>
*/
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*" %>
<html><head><title>Cluster App Test</title></head>
<body>
Server Info:
<%
out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%>
<%
out.println("<br> ID " + session.getId()+"<br>");
// 濡傛灉鏈夋柊鐨?Session 灞炴ц緗?br />
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
out.print("<b>Session 鍒楄〃</b>");
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println( name + " = " + value+"<br>");
System.out.println( name + " = " + value);
}
%>
<form action="index.jsp" method="POST">
鍚嶇О:<input type=text size=20 name="dataName">
<br>
鍊?<input type=text size=20 name="dataValue">
<br>
<input type=submit>
</form>
</body>
</html>
Thread Name: 綰跨▼緇?1-1
Sample Start: 2008-07-13 22:32:42 CST
Load time: 2532
Latency: 2532
Size in bytes: 401
Sample Count: 1
Error Count: 0
Response code: 200
Response message: OK
Response headers:
HTTP/1.1 200 OK
Date: Sun, 13 Jul 2008 14:32:42 GMT
Server: Apache/2.2.9 (Win32) mod_jk/1.2.26
Set-Cookie: JSESSIONID=6A15C0175A2E1EC8E0930FAF0C28ADC9.tomcat1; Path=/lzj1
Thread Name: 綰跨▼緇?1-3
Sample Start: 2008-07-13 22:32:44 CST
Load time: 4
Latency: 4
Size in bytes: 401
Sample Count: 1
Error Count: 0
Response code: 200
Response message: OK
Response headers:
HTTP/1.1 200 OK
Date: Sun, 13 Jul 2008 14:32:44 GMT
Server: Apache/2.2.9 (Win32) mod_jk/1.2.26
Set-Cookie: JSESSIONID=2FF347B788690651E7DADE1A040EE94C.tomcat2; Path=/lzj1
<logic:present name="results">
<table border="1">
<logic:iterate id="element" name="results">
<tr>
<td width="100"><bean:write name="element" property="name"/></td>
<td width="100"><bean:write name="element" property="email"/></td>
<td width="100"><bean:write name="element" property="sname"/></td>
<td width="100"><bean:write name="element" property="times"/></td>
<td id="result"></td>
</tr>
</logic:iterate>
</logic:present>
瀛︾敓錛歵_student
id
name
email
縐戠洰錛歵_subjects
id
subjects name
student_id
鑰冭瘯錛歵_test
id
student_id
subjects_id
month
times
瀛︾敓琛ㄥ拰縐戠洰琛紝瀛︾敓琛ㄥ拰鑰冭瘯琛紝縐戠洰鍜岃冭瘯閮芥槸涓瀵瑰鍏崇郴銆傚緩绔嬪ソ绱㈠紩鍜岀害鏉燂紝鐒跺悗鐢県ibernate鑷姩鐢熸垚hbm鏂囦歡錛屽茍鍦ㄥ鐢熻〃銆佺鐩〃鐨刪bm鏂囦歡閲岃緗甶nverse="true" cascade="all" lazy="true"銆?br />
灝卞ぇ鑷撮厤緗ソ浜嗭紝鐒跺悗鍋囧瑕佸綍鍏ヨ繖鏍蜂竴鏉℃秹鍙婂埌3涓〃鐨勮褰曪細
瀛︾敓濮撳悕銆乪mail銆佺鐩悕縐般佹湀浠姐佽冭瘯嬈℃暟
灝卞彧闇瑕佸啓涓涓畝鍗曠殑鏂規硶璋冪敤session.save灝卞彲浠ヤ繚瀛樻墍鏈夊唴瀹逛簡錛?br />
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm student_registerForm = (DynaActionForm) form;// TODO Auto-generated method stub
//receive from actionform
String strname = student_registerForm.getString("name");
String stremail = student_registerForm.getString("email");
String strsubjectname = student_registerForm.getString("subjectname");
int intmonth = Integer.parseInt(student_registerForm.getString("month"));
int inttimes = Integer.parseInt(student_registerForm.getString("times"));
TStudent tStudent = new TStudent();
tStudent.setName(strname);
tStudent.setEmail(stremail);
//set the subject
TSubjects Tsubjects = new TSubjects();
Tsubjects.setTStudent(tStudent);
Tsubjects.setName(strname);
tStudent.getTSubjectses().add(Tsubjects);
//set the test
TTest Ttest = new TTest();
Ttest.setTStudent(tStudent);
Ttest.setMonth(intmonth);
Ttest.setTimes(inttimes);
tStudent.getTTests().add(Ttest);
//insert all
tstudentDAO.insert(tStudent);
return mapping.findForward("ok");
}
tstudentDAO鍙湁涓涓搷浣滐細
session.save(tStudent);
涔嬪悗鍙互鐪嬪埌3涓〃閲岀殑璁板綍閮藉悓鏃跺鍔犲ソ浜嗐?br />