2024-09-17 00:09:19
1、把数据库建好
CREATE TABLE `User` (
`id` int(11) NOT NULL,
`username` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
)
2、插入一个数据
insert into User values(1,"Martin","12345","zjut")
3、建立一个Dynamic Web Project,目录如下:
4、showinfo.jsp,这里需要注意的是导入类:import="com.entity.User"
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="com.entity.User"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
User user = (User)request.getAttribute("user");
%>
(此处空一行)
id:<%=user.getId() %>
username:<%=user.getUsername() %>
password:<%=user.getPassword() %>
address:<%=user.getAddress() %>
(此处空一行)
<!--
也可以用el表达式,但是同样需要servlet先将值存放在request中,但是用el表达式的话需要在上面加上:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
如下,获取id这样写就可以
${user.getId()}
-->
</body>
</html>
5、结果如下:
2024-09-17 02:04:03
2024-09-17 00:58:02
2024-09-17 01:36:26