2 checkdeyuko checkdeyuko 于 2015.06.25 13:16 提问

学渣妹纸·······servlet,jsp跳转问题 25C

呜呜,学生管理系统。用jsp,servlet,eclipse,mysql编成。貌似是servlet,jsp跳转出现了问题
.求大神帮帮忙。加qq896151657。下面是部分代码

UserLogin.java

package com.servlet;

import com.dao.*;
import com.db.*;
import com.vo.*;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class UserLogin extends HttpServlet {
public UserLogin() {
super();
}

public void destroy() {
super.destroy();

}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("gbk");
request.setCharacterEncoding("gbk");
HttpSession session=request.getSession();
//PrintWriter out=response.getWriter();

    String UserName=request.getParameter("UserName");

String UserPassword=request.getParameter("UserPassword");
User u=null;
UserDao us=null;
if(UserName.equals("")||UserPassword.equals("")){
session.setAttribute("userloginstr","请填写完整");
request.getRequestDispatcher("/UserLoginfail.jsp").forward(request,response);
}else{
u=new User();
us=new UserDao();
u.setUserName(UserName);
u.setUserPassword(UserPassword);
User u1=us.selectInformation(u);
//System.out.println(userName);
//System.out.println(u1.getUserName());
if(UserName.equals(u1.getUserName())&&UserPassword.equals(u1.getUserPassword()))
{
session.setAttribute("userloginname",UserName);
request.getRequestDispatcher("/User.jsp").forward(request,response);
}else{
if(!UserName.equals(u1.getUserName())){
session.setAttribute("userloginstr","没有此管理员");
request.getRequestDispatcher("/UserLoginfail.jsp").forward(request,response);
}else{
session.setAttribute("userloginstr","密码或管理员名不正确");
request.getRequestDispatcher("/UserLoginfail.jsp").forward(request,response);
}
}
}

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);

}

public void init() throws ServletException {

}

}

UserLogin.jsp

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>



UserLogin page



管理员登陆界面



















管理员: (不识别中文,请输入英文)
密 码:
注册新管理员


退出管理员界面




















11个回答

u013263323
u013263323   2015.06.25 13:40

你这有什么问题,问题在哪?

checkdeyuko
checkdeyuko 就是不知道哪里出问题了诶~servlet jsp的跳转
2 年多之前 回复
chunlan0912
chunlan0912   2015.06.25 14:17

麻烦描述一下详细问题,或者报错的界面展示一下。

diaoliwei2
diaoliwei2   Rxr 2015.06.25 14:19

你所谓出现问题的现象是什么啊??

u012736907
u012736907   2015.06.25 17:04

我以前的一段类似的代码,你可以参考一下

 package com.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
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 javax.servlet.http.HttpSession;

import com.Dao.UserDao;
import com.entity.Users;

/**
 * Servlet implementation class UserServlet
 */
@WebServlet(name = "userServlet", urlPatterns = { "/userServlet" })
public class UserServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserServlet() {
        super();
        // TODO Auto-generated constructor stub

    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doPost(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String method = request.getParameter("opt");
        if (method.equals("login")) {
            doLogin(request, response);
        }
    }

    /**
     * 登陆方法
     * 
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void doLogin(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String username = request.getParameter("name");
        String password = request.getParameter("pwd");
        Users users = new Users();
        users.setLoginId(username);
        users.setLoginPwd(password);
        UserDao userDao = new UserDao();
        HttpSession session = request.getSession();
        session.setMaxInactiveInterval(900);
        if (userDao.daLogin(users)) {
            session.setAttribute("users", users);
            RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
            rd.forward(request, response);
        } else {
            RequestDispatcher rd = request.getRequestDispatcher("landing.jsp");
            rd.forward(request, response);
        }
    }
duwiwr282870
duwiwr282870   2015.06.25 18:42

不说错误现象谁能帮你啊……

u014687186
u014687186   2015.06.25 22:25

在eclipse或者myeclipse上面运行的话,如果有错误会报的啊,有没有抛出异常?

zw0283
zw0283   2015.06.25 23:09

额。。。你说的问题是什么啊?MyEclipse有没有报错?还是跳转不到你想要的页面?还是根本进不去后台?

weixin_29321777
weixin_29321777   2015.06.26 09:27

你得把具体报错界面弄出来啊,我们都不清楚你哪里出错

man1hero
man1hero   2015.06.26 15:22

我有大学时候做的课程设计,也是学生管理系统,你要不要。

wutongyu0123wutongyu
wutongyu0123wutongyu   2015.06.26 21:28

你的问题是什么?一堆代码怎么看

共11条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片