Ⅰ web前端代碼 小白求教,web前端開發的代碼,是運行在哪裡,是在web伺服器上運行嗎還是運行在瀏覽器端
運行在瀏覽器端,如果只是HTML5和js,直接在瀏覽器可以。
如果有後台代碼,就得需要web伺服器,目前主流的是Tomcat伺服器。
Ⅱ 在Javaweb開發過程中什麼時候將業務邏輯單獨封裝成一個類用ssh框架做項目的時候我總是分不清業務邏輯
您好,根據我這幾年醬油開發的經驗。一般正規點的大項目基本分為4層,ACTION(表現層),UCC(業務處理層),BS(邏輯處理層),DAO(數據處理層)。其實一般ACTION用來與JSP傳參調用方法什麼的,UCC基本都是用於業務處理,好比銀行貸款方式有各種各樣的貸款,可能是抵押貸款,可能是擔保貸款,當我們去貸款時候,銀行分析出我們是適合抵押還是擔保,但具體抵押要做什麼事情,就是由邏輯層來處理。至於最基本的邏輯層調用數據處理則由DAO來完成。
一般我們都將同一業務邏輯封裝在同一類中,比如商品的買,賣,進貨,出貨,我們可以認為是數量上的變化,可以歸為一類封裝。至於商品的價格,盈虧,我們可以認為是另一類金錢上的變化來封裝。盡快將同一產品的同一屬性封裝在一個類中,這樣以後也方便維護。
- -!大概就是這些,也不知道說沒說清楚,其實我是打醬油的。。。
Ⅲ Web應用層,業務邏輯層,數據訪問層,連接支持層,業務實體層。主要指的是什麼
Web應用層 就是專門放aspx頁面的,裡面只有簡單的數據展示到頁面上的文件。包括一些js。css等等
業務邏輯層 就是處理web應用層和數據訪問層的關聯的,這裡面主要寫一些處理業務邏輯的方法等等。
數據訪問層,就是用來訪問資料庫的,簡單的表的增刪改查。
業務實體層,就是對應資料庫表的,用來保存數據的。
連接支持層 就是一些幫助類
Ⅳ javaweb項目,點擊商品進入商品詳情的業務邏輯
我的思路是這樣的。首先,點擊商品發出post請求,請求參數為商品id。servlet拿到這個id後,查詢資料庫中的數據。查詢出資料庫發送頁面,頁面顯示。
Ⅳ asp.為什麼不在web窗體中處理業務而要創建一個業務邏輯類,怎樣把邏輯單元連接到用戶界面,舉個簡單的例子
1.
對應資料庫實體類
[Serializable]
public class mytable
{
private String _pkid = "";
public String pkid
{
get { return _pkid; }
set { _pkid = value; }
}
private String _a = "";
public String a
{
get { return _a; }
set { _a = value; }
}
}
2.操作類:可以將此類放在業務邏輯層,(如果還要細化,可以將此層放在資料庫實體操作層)
public class mytableDAO
{
private String _ConnectionString;
public mytableDAO(String ConnectionString)
{
this._ConnectionString = ConnectionString;
}
public int New(Entities.MsgRecord obj)
{
String sql = "insert into mytable(pkid,a) values(@pkid,@a)";
SqlConnection cn = new SqlConnection(this._ConnectionString);
SqlCommand cmd = new SqlCommand(sql, cn);
cmd.Parameters.AddWithValue("@a", obj.a);
cmd.Parameters.AddWithValue("@pkid",
String.Empty.Equals(obj.pkid) ? System.Guid.NewGuid().ToString() : obj.pkid);
try
{
if (cn.State != ConnectionState.Open)
cn.Open();
return cmd.ExecuteNonQuery();
}
catch
{
return -1;
}
finally
{
if (cn.State != ConnectionState.Closed)
cn.Close();
}
}
public int Update(Entities.mytable obj)
{
String sql = "Update mytable Set a=@a Where pkid=@ObjectID";
SqlConnection cn = new SqlConnection(this._ConnectionString);
SqlCommand cmd = new SqlCommand(sql, cn);
cmd.Parameters.AddWithValue("@a", obj.a);
cmd.Parameters.AddWithValue("@pkid", obj.pkid);
try
{
if (cn.State != ConnectionState.Open)
cn.Open();
return cmd.ExecuteNonQuery();
}
catch
{
return -1;
}
finally
{
if (cn.State != ConnectionState.Closed)
cn.Close();
}
}
public int Del(Entities.mytable obj)
{
String sql = "delete from mytable Where pkid=@ObjectID";
SqlConnection cn = new SqlConnection(this._ConnectionString);
SqlCommand cmd = new SqlCommand(sql, cn);
cmd.Parameters.AddWithValue("@ObjectID", obj.pkid);
try
{
if (cn.State != ConnectionState.Open)
cn.Open();
return cmd.ExecuteNonQuery();
}
catch
{
return -1;
}
finally
{
if (cn.State != ConnectionState.Closed)
cn.Close();
}
}
public int Del(String where)
{
String sql = String.Format("delete from mytable Where {0}", where.ToLower().Replace("update", "").Replace("delete", ""));
SqlConnection cn = new SqlConnection(this._ConnectionString);
SqlCommand cmd = new SqlCommand(sql, cn);
try
{
if (cn.State != ConnectionState.Open)
cn.Open();
return cmd.ExecuteNonQuery();
}
catch
{
return -1;
}
finally
{
if (cn.State != ConnectionState.Closed)
cn.Close();
}
}
public DataTable Query(String where)
{
String sql = String.Format("select * from mytable Where {0}", where.ToLower().Replace("update", "").Replace("delete", "").Replace("insert", "").Replace(";", "").Replace("--", "").Replace("exec", ""));
try
{
SqlDataAdapter da = new SqlDataAdapter(sql, new SqlConnection(this._ConnectionString));
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
catch
{
return null;
}
}
}
3.界面層,即.在ui中調用:資料庫操作類,如(mytableDao =new mytableDao(conn);)
3.1 新增:
private void NewData()
{
String conn=System.Configuration.ConfigurationManager.ConnectionStrings["dbCon"].ConnectionString
mytableDao =new mytableDao(conn);
mytable obj=new mytable();
obj.a=this.txtbox_a.Text;
obj.b=this.txtbox_b.Text;
obj.c=this.txtbox_c.Text;
.New(obj);
}
3.2 取數據綁定GridView
private void LoadData_InitGridView()
{
String conn=System.Configuration.ConfigurationManager.ConnectionStrings["dbCon"].ConnectionString
mytableDao =new mytableDao(conn);
Table dt=.Query(String.Format(" a ='{0}'",this.txtbox_a.Text));
//gridview
this.GridView1.DataSource=dt;
this.GridView1.DataBind();
//textbox control
this.textbox_a.Text=dt.Rows[0][0].ToString();
}
Ⅵ java使用spring+struts,業務邏輯應該在哪裡寫。
應該在struts層的 action裡面去寫業務邏輯處理。service層是介面 用來調用層的方法。層實現資料庫的操作!
Ⅶ 使用java開發一個web程序。用到JSP頁面,,dto,exception,init,service,action,form和struts框架
首先是一個有表單元素的頁面 用戶通過輸入完成表單 點擊提交,因為是struts1所以先是把用戶表單里輸入的數據通過struts配置文件存到相應的form 然後action從form取到用戶輸入的值,並通過這些值來調用service里的方法,service則是調用里的方法並做業務邏輯處理,而就是基本JDBC的增刪改查語句在通過struts配置文件轉到指定的JSP頁面(這個是流程)。
然後dto是數據傳輸對象, exception是你程序中一些地方的代碼出問題後所出現的異常
至於init是你的action在掉用方法之前的程序默認的方法,(就是指定servlet掉doget或dopost方法)
Ⅷ webservice里做業務邏輯的事情好嗎
webservice 好像是不同程序之間調用比較好吧
Ⅸ web 的controller 層可以進行邏輯處理嗎
1、數據的校驗。
為什麼不在後面的Service層校驗呢?
原因:Service是通用的,而調用方Controller有多個,每一個Controller代表一個業務,這些業務需要校驗的數據又很難統一,所以,每一個Controller自己校驗比較合適,Service只做通用校驗,這樣,當有一個新的Controller接入的時候,Service也不用修改。
2、數據的封裝。
這個就簡單了,因為一個Controller可能調用對個Service才能完成一個請求。
3、數據的轉換。
為什麼不直接使用Service層的數據呢?
原因:一般的Controller層和View層是分離的,如果Controller把Service層的數據重新封裝一下,然後給View,相當於View依賴於Controller,當Service變動之後,Controller修改下映射即可,否則,View要改,Controller也得改(為啥?依賴的jar都變了,能不該嗎)。這也是分層的優點。