目前分類:JSP (182)

瀏覽方式: 標題列表 簡短摘要

31215458_qDC8  

/** *  */package org.app.auth;/** * 用户实体 * @author <a href="mailto:weijunqiang2010@gmail.com">Ajunboys</a> * */public class User {    private Integer no;    private String username;    private String password;    /**     * @return the no     */    public Integer getNo() {        return no;    }    /**     * @param no the no to set     */    public void setNo(Integer no) {        this.no = no;    }    /**     * @return the username     */    public String getUsername() {        return username;    }    /**     * @param username the username to set     */    public void setUsername(String username) {        this.username = username;    }    /**     * @return the password     */    public String getPassword() {        return password;    }    /**     * @param password the password to set     */    public void setPassword(String password) {        this.password = password;    }    /**     * @param no     * @param username     * @param password     */    public User(Integer no, String username, String password) {        super();        this.no = no;        this.username = username;        this.password = password;    }    /**     *      */    public User() {        super();    }        }

 

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

package fifo;import java.util.*;public class FifoSchelduling {    double arriveTime;    double serviceTime;    double starttime;    double donetime;    double runTime;    double weightRunTime;   public FifoSchelduling(){    Map<String,Integer> map=new LinkedHashMap<String,Integer>();   //Insert  A B C D default arrive time  is  1,2,3;   System.out.println("******The FIFO  Schelduling*****");   String string[] =new  String[]{"A","B","C","D"};   map.put("A", 1);   map.put("B", 100);   map.put("C", 1);   map.put("D", 100);      char flag='A';   String temp="";   int time=0;   for(int i=0;i<4;i++){   if(i==0){   System.out.println(flag+" process:");      System.out.println("The "+(char)((int)flag+i)+" startTime is "+i);   System.out.println("doneTime is "+(i+(int)map.get((char)((int)flag+(i))+temp)));   System.out.println("runTime is "+((i+(int)map.get((char)((int)flag+(i))+temp))-i));   System.out.println("weightRunTime "+   ((i+(int)map.get((char)((int)flag+(i))+temp))-i)/(int)map.get((char)((int)flag+(i))+temp)+"\n");   }   else{       time=time+((int)(map.get((char)((int)flag+(i-1))+temp)));       System.out.println((char)(flag+i)+" Process:");       System.out.println("The "+(char)((int)flag+i)+" startTime is "+time);       System.out.println("doneTime is "+(time+(int)map.get((char)((int)flag+(i))+temp)));       System.out.println("runTime is "+((time+(int)map.get((char)((int)flag+(i))+temp))-i));       System.out.println("weigthRuntime "       +((time+(double)map.get((char)((double)flag+(i))+temp))-i)/(double)map.get((char)((double)flag+(i))+temp)+"\n");   }   }   }    }


shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

    package login.util;    import java.sql.Connection;    import java.sql.DriverManager;    import java.sql.PreparedStatement;    import java.sql.ResultSet;    import java.sql.SQLException;    import java.util.ArrayList;    import java.util.List;    public class DBManager<T> {        public static String DRIVER = "com.mysql.jdbc.Driver";        public static String URL = "jdbc:mysql:///db";        public static String USERNAME = "root";        public static String PASSWORD = "root";        /**         * 获取数据库连接         * @return         */        public Connection getConnection() {            Connection conn = null;            try {                Class.forName(DRIVER);                conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);            } catch (ClassNotFoundException e) {                e.printStackTrace();            } catch (SQLException e) {                e.printStackTrace();            }            return conn;        }        /**         * 执行insert update delete SQl         * @param sql SQL语句         * @param params 参数列表         * @return         */        public int executeSQL(String sql, Object... params) {            Connection conn = getConnection();            PreparedStatement ps = null;            int rows = 0;            try {                ps = conn.prepareStatement(sql);                if (params != null && params.length > 0) {                    for (int i = 0; i < params.length; i++) {                        ps.setObject(i + 1, params[i]);                    }                }                rows = ps.executeUpdate();            } catch (SQLException e) {                e.printStackTrace();            } finally {                close(ps, conn);            }            return rows;        }        /**         * 根据Select查询产生Object对象         * @param sql         * @param map         * @param params         * @return         */        public T queryForObject(String sql, IRowMap<T> map, Object... params) {            T obj = null;            Connection conn = getConnection();            PreparedStatement ps = null;            ResultSet rs = null;            try {                ps = conn.prepareStatement(sql);                if (params != null && params.length > 0) {                    for (int i = 0; i < params.length; i++) {                        ps.setObject(i + 1, params[i]);                    }                }                rs = ps.executeQuery();                if (rs.next()) {                    obj = map.mapRow(rs);                }            } catch (SQLException e) {                e.printStackTrace();            } finally {                close(rs, ps, conn);            }            return obj;        }        /**         * 根据SQL查询 返回int类型结果         * @param sql         * @param params         * @return         */        public int queryForInt(String sql, Object... params) {            int obj = 0;            Connection conn = getConnection();            PreparedStatement ps = null;            ResultSet rs = null;            try {                ps = conn.prepareStatement(sql);                if (params != null && params.length > 0) {                    for (int i = 0; i < params.length; i++) {                        ps.setObject(i + 1, params[i]);                    }                }                rs = ps.executeQuery();                if (rs.next()) {                    obj = rs.getInt(1);                }            } catch (SQLException e) {                e.printStackTrace();            } finally {                close(rs, ps, conn);            }            return obj;        }        /**         * 根据Select查询产生List集合         * @param sql         * @param map         * @param params         * @return         */        public List<T> queryForList(String sql, IRowMap<T> map, Object... params) {            List<T> list = null;            Connection conn = getConnection();            PreparedStatement ps = null;            ResultSet rs = null;            try {                ps = conn.prepareStatement(sql);                if (params != null && params.length > 0) {                    for (int i = 0; i < params.length; i++) {                        ps.setObject(i + 1, params[i]);                    }                }                rs = ps.executeQuery();                while (rs.next()) {                    if (list == null) {                        list = new ArrayList<T>();                    }                    T obj = map.mapRow(rs);                    list.add(obj);                }            } catch (SQLException e) {                e.printStackTrace();            } finally {                close(rs, ps, conn);            }            return list;        }        public void close(PreparedStatement ps, Connection conn) {            if (ps != null) {                try {                    ps.close();                } catch (SQLException e) {                    e.printStackTrace();                } finally {                    if (conn != null) {                        try {                            conn.close();                        } catch (SQLException e) {                            e.printStackTrace();                        }                    }                }            }        }        public void close(ResultSet rs, PreparedStatement ps, Connection conn) {            if (rs != null) {                try {                    rs.close();                } catch (SQLException e) {                    e.printStackTrace();                } finally {                    if (ps != null) {                        try {                            ps.close();                        } catch (SQLException e) {                            e.printStackTrace();                        } finally {                            if (conn != null) {                                try {                                    conn.close();                                } catch (SQLException e) {                                    e.printStackTrace();                                }                            }                        }                    }                }            }        }        }

 

 

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

package studyPackage;

import java.io.FileReader;

import java.io.FileWriter;

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

每次用MyEclipse新建Jsp頁面,都要刪除一些無用的代碼,修改pageEncoding. 今天從網上搜索了一下修改Jsp頁面模本的方法:
找到MyEclipse安裝路徑下的MyEclipse\Common\plugins\com.genuitec.eclipse.wizards_9.0.0.me201103012021.jar(我用的是MyEclipse9.0,其他版本大致也是一樣的)。
把 com.genuitec.eclipse.wizards_9.0.0.me201103012021.jar這個jar包複製出來,解壓後,找到這個 路徑下的templates\jsp\Jsp.vtl 這個Jsp頁面的範本檔,用記事本打開:(下面//後是對範本檔做的注解,請仔細看)

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

package crawler;

import java.util.BitSet;

public class BloomFilter {
    private int defaultSize = 5000 << 10000;
    private int basic = defaultSize - 1;
    private BitSet bits = new BitSet(defaultSize);

    private int[] lrandom(String key) { // 产生八个随机数并返回
        int[] randomsum = new int[8];
        for (int i = 0; i < 8; i++)
            randomsum[0] = hashCode(key, i + 1);
        return randomsum;
    }
   
    // 将一个URL加入
    public synchronized void add(String key) {
        int keyCode[] = lrandom(key);
        for (int i = 0; i < 8; i++)
            bits.set(keyCode[i]); // 将指定索引处的位设置为 true
        }
    }

    // 判断一个URL是否存在
    public boolean exist(String key) {
        int keyCode[] = lrandom(key);
        if (bits.get(keyCode[0])
                && bits.get(keyCode[1]) // 返回指定索引处的位值。
                && bits.get(keyCode[2]) && bits.get(keyCode[3])
                && bits.get(keyCode[4]) && bits.get(keyCode[5])
                && bits.get(keyCode[6]) && bits.get(keyCode[7])) {
            return true;
        }
        return false;
    }


    private int hashCode(String key, int Q) {
        int h = 0;
        int off = 0;
        char val[] = key.toCharArray(); // 将此URl转换为一个新的字符数组
        int len = key.length();
        for (int i = 0; i < len; i++) {
            h = (30 + Q) * h + val[off++];
        }
        return basic & h;
    }

    
     /* public static void main(String[] args) { // TODO Auto-generated method
      long pre = 0;
      long post = 0;
      pre = System.nanoTime();
          BloomFilter f = new BloomFilter(); //初始化
      f.add("http://www.agrilink.cn/"); f.add("http://www.baidu.com/");
      System.out.println(f.exist("http://www.baidu.com/"));
      System.out.println(f.exist("http://www.baidud.com/"));
      post = System.nanoTime();
      System.out.println("Time: " + (post - pre));
      
      }
     */

}

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

<%@page import="java.util.regex.Matcher"%>
<%@page import="java.util.regex.Pattern"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%!

// \b 是单词边界(连着的两个(字母字符 与 非字母字符) 之间的逻辑上的间隔),
// 字符串在编译时会被转码一次,所以是 "\\b"
// \B 是单词内部逻辑间隔(连着的两个字母字符之间的逻辑上的间隔)
String phoneReg = "\\b(ip(hone|od)|android|opera m(ob|in)i"
                +"|windows (phone|ce)|blackberry"
                +"|s(ymbian|eries60|amsung)|p(laybook|alm|rofile/midp"
                +"|laystation portable)|nokia|fennec|htc[-_]"
                +"|mobile|up.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";
String tableReg = "\\b(ipad|tablet|(Nexus 7)|up.browser"
                +"|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";
Pattern phonePat = Pattern.compile(phoneReg, Pattern.CASE_INSENSITIVE);
Pattern tablePat = Pattern.compile(tableReg, Pattern.CASE_INSENSITIVE);

public boolean checkMobile(String userAgent){
        if(null == userAgent){
                userAgent = "";
        }
        // 匹配
        Matcher matcherPhone = phonePat.matcher(userAgent);
        Matcher matcherTable = tablePat.matcher(userAgent);
        if(matcherPhone.find() || matcherTable.find()){
                return true;
        } else {
                return false;
        }
}
%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

//
String userAgent = request.getHeader( "USER-AGENT" ).toLowerCase();

if(null == userAgent){
        userAgent = "";
}
if(checkMobile(userAgent)){
        response.sendRedirect(basePath+"download.html");
        //request.getRequestDispatcher("/download.html").forward(request,response);
} else {
        response.sendRedirect(basePath+"index.html");
        //request.getRequestDispatcher("/index.html").forward(request,response);
}
//
%>

<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <base href="<%=basePath%>">
    
    <title>测试移动设备跳转</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="key<a href="http://www.it165.net/edu/ebg/" target="_blank" class="keylink">word</a>s" content="测试,移动设备,跳转">
        <meta http-equiv="description" content="测试移动设备跳转">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
  </head>
  
  <body>
  
  <div id="pagecontent" style="min-height:500px;_height:500px;">
  
    正在运行!<br>
  </div>
    
  </body>
</html>

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

UrlEncode:將字串以URL編碼
傳回值:字串
函數種類:編碼處理

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

if (FileUpload.isMultipartContent(requestCoNtext)) {

 

DiskFileItemFactory factory = new DiskFileItemFactory();

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

跳轉分兩部分,一是發生在servlet,一是在JSP,其實JSP也就是servlet,不過還是有點差異滴。

 

Servlet:

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<head>

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

1、加入jsoup-1.6.2.jar

 

2、準備好url

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

Parameters Value
d 4
b 2
c 3
a 1

PrtReqParas.java

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

Header Value
host 127.0.0.1
connection keep-alive
cache-control max-age=0
accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
user-agent Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36
accept-encoding gzip,deflate,sdch
accept-language en-US,en;q=0.8

PrintRequestHeaders.java

 

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

原文:HTTP://www.java2000.net/p1010

 

第一步,登陸的時候一旦選擇了[自動登入]的選項,則需要在登陸成功後,附加下面的代碼

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

<%@page import="System.Data.DataRow"%>
<%@page import="System.Data.DataTable"%>
<%@page import="DAL.DBUtil"%>

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

/**********************
function : oCookieRecord
author : Der [http://hi.baidu.com/jasyyy]
lastodify : 2010-04-22
***********************/

//setCookie
function setCookie(name, value, days, path, domain, secure) {
        var sCookie = name + "=" + encodeURIComponent(value);
        if (days) {
                var _exp = new Date();
                _exp.setTime(_exp.getTime() + days * 24 * 60 * 60 * 1000);
                sCookie += "; expires=" + _exp.toGMTString();
        }
        if (path) {
                sCookie += "; path=" + path;
        } else {
                sCookie += "; path=/";
        }
        if (domain) {
                sCookie += "; domain=" + domain;
        }
        if (secure) {
                sCookie += "; secure=";
        }
        document.cookie = sCookie;
}

//getCookie
function getCookie(name) {
        var sRE = "(?:; )?" + name + "=([^;]*);?";
        var oRE = new RegExp(sRE);
        return (oRE.test(document.cookie)) ? decodeURIComponent(RegExp["$1"]) : null;
}

//delCookie
function delCookie(name, path) {
        setCookie(name, "", -1, path);
}

//CookieRecord
var oCookieRecord = new Object();
//setCookieRecord
oCookieRecord.set = function(oParam) {
        //配置参數
        var sTitleFilter = oParam.sTitleFilter,
        // title內容後綴篩選
        sRecordListId = oParam.sRecordListId,
        //瀏覽記錄id
        sRecordListTagName = oParam.sRecordListTagName,
        //瀏覽記錄標簽名
        nRecordListLength = oParam.nRecordListLength,
        //瀏覽記錄限制條數
        nExpires = oParam.nExpires,
        //cookie保留天數
        sCookiePath = oParam.sCookiePath,
        //限制cookie訪問路徑
        sDomain = oParam.sDomain,
        //限制cookie域
        bSecure = oParam.bSecure; //限制cookie是否为安全網站訪問
        //参數默認值設置

        if (!sCookiePath) {
                sCookiePath = "/";
        }

        //setCookie record
        var path = window.location.pathname.split("/");
        var pathN = path[path.length - 1].split(".")[0];

        //篩選帶逗號的同一篇文章
        if (pathN.indexOf(",") > -1) {
                pathN = pathN.slice(0, pathN.indexOf(","));
        }
        var articleTitle = document.title;

        //title後綴篩選
        if (sTitleFilter && sTitleFilter != "") {
                var tIndex = articleTitle.indexOf(sTitleFilter);
                if (tIndex > -1) {
                        var tLen = sTitleFilter.length;
                        var aLen = articleTitle.length;
                        articleTitle = articleTitle.slice(0, tIndex) + articleTitle.slice(tIndex + tLen, aLen);
                }
        }
        var sValue = location.href + "^_^" + articleTitle;
        setCookie(pathN, sValue, nExpires, sCookiePath, sDomain, bSecure);

        //getRecordList
        var oCookieList = decodeURIComponent(document.cookie).split(";");
        var cookieList = [];
        var oFragment = document.createDocumentFragment();

        //篩選其他地方創建的cookie
        for (var i = 0,
        len = oCookieList.length; i < len; i++) {
                if (oCookieList[i].split("=")[1].indexOf("^_^") > -1) {
                        cookieList.unshift(oCookieList.slice(i, i + 1).toString());
                }
        }

        //cookie數超出刪除
        var len = cookieList.length;
        if (len > nRecordListLength) {
                for (var i = len - 1; i > nRecordListLength - 1; i--) {
                        delCookie(cookieList[i].split("=")[0], sCookiePath);
                        cookieList.pop();
                }
        }

        // 瀏覽記錄填充
        for (var i = 0; i < cookieList.length; i++) {
                //creat tag
                var aCookie = cookieList[i].split("=")[1].split("^_^");
                var aCookieLen = aCookie.length;
                var aLink = aCookie[0];
                var aTitle = "";

                //篩選符號^_^
                if (aCookieLen > 2) {
                        for (var j = 1; j < aCookieLen; j++) {
                                if (j < aCookieLen - 1) {
                                        aTitle += aCookie[j] + "^_^";
                                } else {
                                        aTitle += aCookie[j];
                                }
                        }
                } else {
                        aTitle = aCookie[1];
                }

                //
                var aListTag = document.createElement(sRecordListTagName);
                var a = document.createElement("a");
                var aText = document.createTextNode(aTitle);

                //append tag
                a.setAttribute("href", aLink);
                a.setAttribute("target", "_blank");
                a.appendChild(aText);
                aListTag.appendChild(a);
                oFragment.appendChild(aListTag);
        }
        document.getElementById(sRecordListId).innerHTML = "";
        document.getElementById(sRecordListId).appendChild(oFragment);
}

//delCookieRecord
oCookieRecord.del = function(sRecordListId) {
        if (document.cookie != "") {
                //清空cookie
                var cookieList = decodeURIComponent(document.cookie).split(";");
                for (var i = 0,
                len = cookieList.length; i < len; i++) {
                        if (cookieList[i].split("=")[1].indexOf("^_^") > -1) {
                                delCookie(cookieList[i].split("=")[0]);
                        }
                }
        }

        //清空記錄
        document.getElementById(sRecordListId).innerHTML = "";
}

 

 html:

 

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

The servlet which implements Jasper is configured using init parameters in your global$CATALINA_BASE/conf/web.xml.

  • checkInterval - If development is false and reloading is true, background compiles are enabled. checkInterval is the time in seconds between checks to see if a JSP page needs to be recompiled. Default 300 seconds.
  • compiler - Which compiler Ant should use to compile JSP pages. See the Ant documentation for more information. If the value is not set, then the default Eclipse JDT Java compiler will be used instead of using Ant. No default value.
  • classdebuginfo - Should the class file be compiled with debugging information? true or false, default true.
  • classpath - What class path should I use while compiling generated servlets? By default the classpath is created dynamically based on the current web application.
  • compilerSourceVM - What JDK version are the source files compatible with? (Default JDK 1.4)
  • compilerTargetVM - What JDK version are the generated files compatible with? (Default JDK 1.4)
  • development - Is Jasper used in development mode (will check for JSP modification on every access)? true orfalse, default true.
  • enablePooling - Determines whether tag handler pooling is enabled. true or false, default true.
  • engineOptionsClass - Allows specifying the Options class used to configure Jasper. If not present, the default EmbeddedServletOptions will be used.
  • ieClassId - The class-id value to be sent to Internet Explorer when using <jsp:plugin> tags. Defaultclsid:8AD9C840-044E-11D1-B3E9-00805F499D93.
  • fork - Have Ant fork JSP page compiles so they are performed in a seperate JVM from Tomcat? true or false, default true.
  • javaEncoding - Java file encoding to use for generating java source files. Default UTF8.
  • genStrAsCharArray - Should text strings be generated as char arrays, to improve performance in some cases? Default false.
  • keepgenerated - Should we keep the generated Java source code for each page instead of deleting it? true orfalse, default true.
  • mappedfile - Should we generate static content with one print statement per input line, to ease debugging? trueor false, default true.
  • modificationTestInterval - Checks for modification for a given JSP file (and all its dependent files) will be performed only once every specified amount of seconds. Setting this to 0 will cause the JSP to be checked on every access. Default is 4 seconds.
  • reloading - Should Jasper check for modified JSPs? true or false, default false.
  • scratchdir - What scratch directory should we use when compiling JSP pages? Default is the work directory for the current web application.
  • trimSpaces - Should white spaces in template text between actions or directives be trimmed ?, default false.

 

The Java compiler from Eclipse JDT in included as the default compiler. It is an advanced Java compiler which will load all dependencies from the Tomcat class loader, which will help tremendously when compiling on large installations with tens of JARs. On fast servers, this will allow sub-second recompilation cycles for even large JSP pages. This new compiler will be updated to support the Java 5 syntax as soon as possible.

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()

獲取系統時間具體操作:

import="java.util.Date,java.text.SimpleDateFormat“

這個必須插入
獲取時間:

shadow 發表在 痞客邦 PIXNET 留言(0) 人氣()