老师,为什么网页跳转不了?

老师,为什么网页跳转不了?

http://img1.sycdn.imooc.com//climg/60eebe04085461ab09250361.jpg

文件结构

http://img1.sycdn.imooc.com//climg/60eebe340852e8ce05130504.jpg

代码

login.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>login page</title>
<style type="text/css">
body{
maring:0px;
padding:0px;
}
body .login{
width:260px;
border:solid 1px black;
border-radius:5px;
}
body .login .header{
width:260px;
height:36px;
background-color:#99cc00;
color:white;
}
body .login .content{
margin-left:26px;
margin-top:10px;
}
body .login .header .logo{
width:260px;
line-height:36px;
margin-left:26px;
}
body .login .user_password{
margin-bottom:10px;
}
body .login .user_password .line_password{
font-size:10px;
}
body .login .user_name{
margin-bottom:10px;
}
body .login .user_name .line_name{
font-size:10px;
}
body .login .content .user_name .name{
width:200px;
}
body .login .content .user_password .password{
width:200px;
}
body .login .content .user_button .submit{
margin-bottom:10px;
color:white;
background-color:#99cc00;
width:60px;
height:23px;
lien-height:20px;
font-size:10px;
//border:solid 1px black;
border-radius:5px;
}
</style>
</head>
<body>
<form action="http://localhost:8080/demo13and14zhou1jie2zhang5/loginCheck" method="post">
<!-- <form action="http://demo13and14zhou1jie2zhang5/loginCheck" method="post"> -->
<div class="login">
<div class="header">
<div class="logo">系统登录</div>
</div>
<div class="content">
<div class="user_name">
<div class="line_name">用户名:</div>
<input type="text" class="name" name="userName"/>
</div>
<div class="user_password">
<div class="line_password">密码:</div>
<input type="password" class="password" name="userPassword"/>
</div>
<div class="user_button">
<input type="submit" class="submit" value="登录"/>
</div>
</div>
</div>
</form>
</body>
</html>

LoginCheckServlet.java

package servlet;
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;
/**
* Servlet implementation class LoginCheckServlet
*/
@WebServlet("/loginCheck")
public class LoginCheckServlet extends HttpServlet {
private static String user_name="ycLin";
private static String user_password="6666";
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public LoginCheckServlet() {
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userName=request.getParameter("userName");
String userPassword=request.getParameter("userPassword");
if((userName.equals(user_name))&&(userPassword.equals(user_password))) {
/*
* //request.getRequestDispatcher(
* "http://localhost:8080/demo13and14zhou1jie2zhang5/loginPass.html").forward(
* request,response);
*/
/*
* //request.getRequestDispatcher("loginPass.html").forward(request,response);
* //response.sendRedirect("/demo13and14zhou1jie2zhang5/loginPass.html");
*/
response.sendRedirect("http://127.0.0.1:8080/demo13and14zhou1jie2zhang5/loginPass.html");
}
}
}


loginPass.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>login pass page</title>
<style type="text/css">
body{
margin:0px;
padding:0px;
overflow:hidden;
position:positive;
}
body .page{
width:100%;
float:left;
overflow:hidden;
position:positive;
}
body .page .image{
//width:1530px;
//height:493px;
//height:100%;
width:100%;
height:760px;
float:left;
overflow:hidden;
position:positive;
}
</style>
</head>
<body>
<div class="page">
<image src="loginPass.jpg" alt="啊这。。、- - 页面出错了"/ class="image">
</div>
</body>
</html>


正在回答

登陆购买课程后可参与讨论,去登陆

3回答

同学你好,因为loginPass.html是在WEB-INF目录下,WEB-INF目录下的文件是不能直接访问的,如果直接访问就会报404,也就是同学上述贴出截图的异常

祝学习愉快~




  • 慕函数4309305 提问者 #1

    那loginPass.html一定要放WEB-INF下怎么才能跳转到呢老师

    2021-07-14 19:30:17
  • 慕函数4309305 提问者 #2

    我这可是从Servlet跳转啊,为什么不能跳转到啊老师

    2021-07-14 19:33:15
慕函数4309305 提问者 2021-07-14 19:12:44

可以了老师

request.getRequestDispatcher("/loginPass.jsp").forward(request,response);


loginPass.html改成loginPass.jsp


loginPass.jsp从WebContent/WEB-INF移到WebContent

就可以了

http://img1.sycdn.imooc.com//climg/60eec69a086d9cb919200693.jpg

http://img1.sycdn.imooc.com//climg/60eec6a9089ef61e19201025.jpg

  • 同学你好,非常棒,解决问题就好,继续加油哇~

    祝学习愉快~

    2021-07-14 19:14:55
  • 提问者 慕函数4309305 #2

    老师,为什么loginPass.jsp放到WEB-INF下不能跳转,要怎么才能跳转到?

    2021-07-14 19:26:44
  • 提问者 慕函数4309305 回复 好帮手慕小脸 #3

    谢谢老师的鼓励~

    2021-07-14 19:35:20
慕函数4309305 提问者 2021-07-14 18:44:44
  • 提问者 慕函数4309305 #1

    login.html,loginPass.html,loginServelt单独访问都可以啊

    2021-07-14 18:46:24
  • 提问者 慕函数4309305 #2

    笔误,纠正一下,是loginCheck的Servlet不是loginServlet

    2021-07-14 18:48:08
  • 提问者 慕函数4309305 #3

    救救孩子吧老师!...心态要崩了​

    2021-07-14 18:56:38
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师