[Java] 纯文本查看 复制代码
JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
public User check_login(User loginuser) { String sql = "select * from login_user where username = ? and password = ?"; User user = template.queryForObject(sql,
new BeanPropertyRowMapper<User>(User.class),
loginuser.getUsername(), loginuser.getPassword());
return user;
}
问题答案 问题分析: [AppleScript] 纯文本查看 复制代码
try{
User user = template.queryForObject(sql,
new BeanPropertyRowMapper<User>(User.class),
loginuser.getUsername(), loginuser.getPassword());
return user;
}catch (Exception e){
return null;
}
[Java] 纯文本查看 复制代码
public class DownloadServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取路径中请求参数的值,就是图片的名称
String filename = request.getParameter("filename");
// 获取Context对象,来获取图片的服务器路径
ServletContext context = this.getServletContext();
String realPath = context.getRealPath(filename);
// 根据路径创建字节输入流对象,读取文件使用
FileInputStream fis = new FileInputStream(realPath);
// 设置响应头属性,在点击之后出现附件弹窗,指定MIME类型
filename = DownLoadUtils2.getFileName(request.getHeader("user-agent"),filename);
response.setHeader("content-disposition", "attachment;filename=" + filename);
response.setHeader("content-type", filename);
// 读取文件并输出到浏览器
byte[] bytes = new byte[1024 * 8];
int len = 0;
// 获取输出流对象
ServletOutputStream sos = response.getOutputStream();
while ((len = fis.read(bytes)) != -1) {
sos.write(bytes,0,len);
}
fis.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
[HTML] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>下载</title>
<script>
window.onload=function () {
var image = document.getElementById("image");
image.onclick=function () {
image.href="/downloadServlet?filename=九尾.jpg"
}
}
</script>
</head>
<body>
<a href="/downloadServlet" id="image">图片1</a>
</body>
</html>