resp.sendRedirect("main.jsp");报500错误 5C

package Methods;
import java.io.File;
import java.io.IOException;
import java.util.List;

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 org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.dom4j.tree.DefaultElement;

@WebServlet("/user/login")
public class Dom4j extends HttpServlet{

String Name;
String Password;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    super.doPost(req, resp);
}

@SuppressWarnings("null")
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
         {

    // TODO Auto-generated method stub
    try {
        super.doPost(req, resp);
    } catch (ServletException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

     Name=req.getParameter("txtUserName");
     Password=req.getParameter("txtPassword");

    System.out.println("dsafsd");
    System.out.println(Password);
    Boolean a=login();

    if(a)
    {

    try {
        **resp.sendRedirect("main.jsp");**
        return;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


     }
    else{
try {
**      resp.sendRedirect("MyJsp.jsp");**

        return;

    } 
    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

     }

}


public Boolean  login(){



     String path="C:\\Users\\25527\\Desktop\\test\\src\\Methods\\account.xml";
     File file=new File(path);
     SAXReader sr=new SAXReader();
     sr.setEncoding("GB18030");
     int a=-1;

     try {
        Document doc=sr.read(file);
    Element root=doc.getRootElement();
        List<Element> empList=root.elements();
        for(Element empEle: empList)
        {
          Element nameEle=empEle.element("ID");
          String name=nameEle.getTextTrim();
          Element word=empEle.element("password");
          String mima=word.getTextTrim();
          if(name.equals(Name)&& mima.equals(Password))
          { 
            a=1;
            break;
          }

      //或者 String namer=empEle.elementText("name");
        }


    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     if(a==1)
     {
    return true;
     }
     else{
         return false;
     }



}

}

1个回答

定位下问题,把报错信息发出来

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐