vendredi 1 juillet 2016

request.getAttribute is null when I call it in jsp

It calls Servlet by click a href.

    <li ><a href="<%=request.getContextPath() %>/ProviderServlet">privilegeManagement</a></li>

this code is include in the navigation.jsp which is included in the main.jsp.

then it's my servlet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // TODO Auto-generated method stub
    ProviderDao pd  = new ProviderDao();
    List<ProviderArchives> list = pd.getArchives();
    String str = "chenfeng";
    req.setAttribute("list", list);
    req.setAttribute("hu" , str);
    getServletContext().getRequestDispatcher("/jsp/main.jsp").forward(req,resp);
}

then it's my main.jsp.

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.*"%>
<%@page import="com.chenfeng.javabean.ProviderArchives"%>
<%@ taglib prefix="c"    uri="http://ift.tt/QfKAz6" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ift.tt/kTyqzh">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>main</title>
</head>
<body>
    <%@ include file="navigation.jsp"%>
    <div>
        <%@ include file="management.jsp"%>
    </div>
    <div>
      <%
             String k = (String)request.getAttribute("hu");
             out.println(k);
      %>
       <c:forEach items="${list}"  var="item">
       <tr> 
        <td>${item.provideID() }</td> 
        <td>${item.GID }</td> 
        <td>${item.Gname }</td> 
        <td>${item.PID }</td> 
        <td>${item.TEL }</td> 
        <td>${item.ADDR }</td>
        <td> 
         <a href="QueryUserByIdServlet?id=${item.provideID }">Modify</a> 
         <a href="DeleteUserServlet?id=${item.provideID }">Delete</a> 
        </td> 
       </tr> 
      </c:forEach> 
    </div>
</body>
</html>

then when I run this on server,it shows like this result thank in advance for any help!




Aucun commentaire:

Enregistrer un commentaire