2013年2月26日 星期二

第一隻 JSP





如要將請求轉發另一JSP 頁面處理,可使用標準頁籤<jsp:forward>,例如:jsp:forward page="sayYes.jsp">, 目前頁面會生成一個servlet,sayYes 即為一個Servlet。
Response的職責將被指派給被forward的對象。如果要傳遞參數時可以搭配<jsp:param >動作元素指定參數給被forward的對象。forward的對象回應之後,執行流程會回到原頁面,你可以再進行一些陳述執行,不過無法再作任何回應







2013年2月24日 星期日

開啟Eclipse 出現 Fail to create the Java Virtual Machine





開啟Eclipse 出現 Fail to create the Java Virtual Machine。



爬文之後發現問題出現在Eclipse.ini 檔中的


-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20120522-1813
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Dhelp.lucene.tokenizer=standard
-Xms40m
-Xmx512m

將256 M改為128 M 即可正常啟動

2013年2月19日 星期二

Web 伺服器和Tomcat

一般所謂的Web 伺服器,是指一種軟體。管理Servlet /JSP 並不屬於Web 伺服器的權責,而是交由Web 容器(亦稱為Servlet/JSP )容器。當Web 伺服器收到用戶端瀏覽器的請求時,將其轉發給Web 容器,Web 容器呼叫對應的Servlet 回應請求,Web伺服器再將Web 容器的回應發送給用戶端瀏覽器。

2013年2月2日 星期六

Web 控制項 避免重複觸發 Button



1.
屬性中 OnClientClick 設定 disabled=true;this.form1.submit();
UseSubmitBehavious=false,將產生下列的_doPostBack











執行結果


2.或者可以在Code Behind 程式碼中加上


/* Sensor 代表觸動事件來源物件,e為傳遞給該事件的額外描述
在畫面上的點選動作,可用e來擷取

*/
 protected void Button1_Click(object sender, EventArgs e)
    {
        Button1.Enabled = false;
    }


ASP .NET Web 控制項(TextView)



在工具列拉一個TextBox 的控制元件,放到HTML 中








修改屬性中的AutoPostBack 設為true,當滑鼠移到其他控制項時,會自動執行送出的動作。




選擇屬性中的事件(閃電符號),選取TextChanged 事件 TextBox1_TextChange



TextBox.aspx






<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TextBox.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <!-- 控制項一定要放在FORM 內
    
    -->
    <form id="form1" runat="server">
    <div>
    
       欄位1: 
        <asp:TextBox ID="TextBox1" runat="server" 
        AutoPostBack="True" ontextchanged="TextBox1_TextChanged" 
            ></asp:TextBox>
            <!-- 設定AutoPostBack="True",當滑鼠移到其他控制項時,
            會自動執行送出的動作
            -->
        <br />
       欄位2: <asp:TextBox ID="TextBox2" runat="server" 
            ontextchanged="TextBox2_TextChanged1"></asp:TextBox>
    
    </div>
    </form>
</body>
</html>



=================================================================
後置程式碼的部分


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    //ASP.NET 程式中最早被執行的 
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("Page_Load");
    }
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        Response.Write("TextChanged 被觸發");
    }
    protected void TextBox2_TextChanged1(object sender, EventArgs e)
    {

    }
}



執行結果

Key 上aaa 滑鼠移到其他地方時