servlet(三)解决乱码以及访问数据库

1. 表单中文参数值乱码问题

(1)为什么会有乱码?

表单提交时,浏览器会对表单中的中文参数值进行编码(会使用打开
该表单所在的页面时的字符集来编码),服务器端默认会使用
"iso-8859-1"来解码。所以会产生乱码。

(2)如何解决

1)post请求

2)get请求


Servlet访问数据库

    1.导包


step2. 将config.properties文件添加到resource文件夹下面

step3.修改DButil


step4. 测试DBUtil类。
注:可以使用junit来测试(junit是一个单元测试工具)。

step5. 建立t_emp表

create table t_emp(
    id number(8) primary key,
    name varchar2(50),
    salary number(8,2),
    age number(3)
);
create sequence t_emp_seq;

step6. 添加Employee类。
step7. 添加EmployeeDAO类,并测试。
step8. AddEmpServlet调用EmployeeDAO。

猜你喜欢

转载自blog.csdn.net/qq_41264674/article/details/80464737