JAVAEE课程(八)

jdbc

jdbc代码

import java.sql.*;

依然是关于丑陋的字符串常量,对于一些常量可以这么写:

public class Main {
    public static void main(String[] args) {
        String driverClassName = null;
        Class.forName(driverClassName):
    }
}

链接池

性能太差了。数据库直连每次要花100多ms来建立和关闭链接。

于是使用一个链接池,在链接用完之后可以设定为空闲。

import javax.sql.DataSource;
import javax.servlet.*;

public class AServlet extends {
    public static void main(String[] args) {
        DataSource ds = (DataSource) ctx.lookup("jdbc/TestDB");
        getServletContext().setAttribute("ds", ds);
    }
}

i18n

internationalization
java.util.Locale
java.util.ResourceBundle bundle = new ResourceBundle("res", )
bundle.getString("button.Add");
res.properties
res_en.properties
res_jp.properties
res_zh_CN.properties
<input type="submit" value="add">
button.add=Add

JNDI

java命名服务, java naming and directory interface

NamingContext
    Context ctx = 
    Cart c = (Cart) ctx.lookup("/abc/xyz/cart/");
    Context c1 = (Context) ctx.lookup("/abc"); // forms the 
    Cart c2 = (Cart) c1.lookup("/xyz/cart/);
    assert c1 == c2;

    lookup(String s);
    bind(String name, Object o);
    rebind(String name, Object o);

MVC

Controller没有可移植性,而V和M都有

为了提高它的可复用性,“降低程序的密度就可以提高可复用性”

Struts 1.

是一个MVC框架。

提供了一大堆类,FrontEndController & BackEndController. 前端控制器由ActionServlet充当。

ActionServlet.execute(ActionMapping mapping, ActionForm form, 
                      HttpServletRequest request, HttpServletResponse response) {

                      }
<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</utl-pattern>
</servlet-mapping>

<action
    path="/InputSubmit"
    type="app.InputSubmit"/>

考试题

<Context>
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.?" 
    maxTotal="100" maxIdle="30" maxWaitMillis = "10" 
    username="javauser" password="javadude" driverClassName="com.mysql"/>
</Context>
  • Struts

回去自己学的

  • 设计模式
  • JNDI
  • InitialContext(Hashtable);
  • ActionServlet
  • DispatchAction
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值