404错误
# 具体遇到的问题
# 报错信息的截图
# 相关课程内容截图
# 尝试过的解决思路和结果
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
在这里输
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>欢迎使用油画商城</title>
<meta name="keywords" content="HTML5 Bootstrap 3 Admin Template UI Theme" />
<meta name="description" content="AbsoluteAdmin - A Responsive HTML5 Admin UI Framework">
<meta name="author" content="AbsoluteAdmin">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/assets/skin/default_skin/css/theme.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/assets/admin-tools/admin-forms/css/admin-forms.css">
<link rel="shortcut icon" href="${pageContext.request.contextPath }/assets/img/favicon.ico">
</head>
<body class="external-page external-alt sb-l-c sb-r-c">
<div id="main" class="animated fadeIn">
<section id="content_wrapper">
<section id="content">
<div class="admin-form theme-info mw500" id="login">
<div class="content-header">
<h1>油画商城</h1>
<p class="lead">欢迎使用油画商城自动化管理系统</p>
<font color='red'>${msg}</font>
</div>
<div class="panel mt30 mb25">
<form method="post" action="${pageContext.request.contextPath}/UserServlet1" id="contact">
<input type="hidden" name="method" value="login">
<div class="panel-body bg-light p25 pb15">
<div class="section">
<label for="sn" class="field-label text-muted fs18 mb10">名称</label>
<label for="sn" class="field prepend-icon">
<input type="text" name="username" id="username" class="gui-input" placeholder="请输入名称...">
<label for="sn" class="field-icon">
<i class="fa fa-user"></i>
</label>
</label>
</div>
<div class="section">
<label for="password" class="field-label text-muted fs18 mb10">密码</label>
<label for="password" class="field prepend-icon">
<input type="password" name="password" id="password" class="gui-input" placeholder="请输入密码...">
<label for="password" class="field-icon">
<i class="fa fa-lock"></i>
</label>
</label>
</div>
</div>
<div class="panel-footer clearfix text-center">
<button type="submit" class="button btn-primary mr10"> 登陆 </button>
</div>
</form>
</div>
</div>
</section>
</section>
</div>
<script src="vendor/jquery/jquery-1.11.1.min.js"></script>
<script src="vendor/jquery/jquery_ui/jquery-ui.min.js"></script>
<script src="assets/js/utility/utility.js"></script>
<script src="assets/js/demo/demo.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>
package com.imooc.web.action;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.imooc.domain.User;
import com.imooc.service.UserService;
import com.imooc.service.impl.UserServiceImpl;
@WebServlet("/UserServlet1")
public class UserServlet1 extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//接受前台传入的数据
String s=request.getParameter("method");
if("login".equals(s)) {
login(request,response);
}else if("logout".equals(s)) {
logout(request,response);
}
}
private void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
//1、销毁session
request.getSession().invalidate();
//2、进行重定向
response.sendRedirect(request.getContextPath()+"/login.jsp");
}
/**
* 实现登录操作
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
private void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username=request.getParameter("username");
String password=request.getParameter("password");
System.out.println(username+password);
//封装数据
User user=new User();
user.setUsername(username);
user.setPassword(password);
//处理数据
UserService userservice=new UserServiceImpl();
//返回值是User,参数为user
User users=userservice.login(user);
//处理完数据后,完成页面跳转
if(users==null) {
//登录失败
//返回登录页面
request.setAttribute("msg", "用户名或者密码错误");
//请求的转发
request.getRequestDispatcher("/login.jsp").forward(request, response);
//登录成功
//将用户信息进行保存,进行页面的跳转
request.getSession().setAttribute("users", users);
//进行重定向
request.getRequestDispatcher("/admin/category_list.jsp").forward(request, response);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
package com.imooc.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.imooc.dao.UserDao;
import com.imooc.domain.User;
import com.imooc.utils.JDBCUtils;
public class UserDaoImpl implements UserDao {
@Override
public User login(User user) {
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet res=null;
try {
//获得连接
conn=JDBCUtils.getConnection();
//编写sql语句
String sql="select * from user where username=?,password=?";
//预编译
pstmt.setString(1,user.getUsername());
pstmt.setString(2,user.getPassword());
pstmt=conn.prepareStatement(sql);
//获取结果集
res=pstmt.executeQuery();
while(res.next()) {
user.setUid(res.getInt("uid"));
user.setUsername(res.getString("username"));
user.setPassword(res.getString("password"));
}
}catch (Exception e) {
e.printStackTrace();
}finally {
//资源释放
JDBCUtils.release(res, pstmt, conn);
}
return user;
}
}
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星