Servlet向jsp传值,为什么jsp页面总是null呢?求解
servlet:publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throws...
servlet:public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); String username=request.getParameter("txt1"); request.setAttribute("username",username); RequestDispatcher rd = request.getRequestDispatcher("/WebRoot/charesult.jsp"); rd.forward(request, response); }jsp:<%String username=(String)request.getAttribute("username");out.println(username);%>
展开
2013-10-31
展开全部
你的代码都是正确的,你可以调试看看,看你servlet页面的String username=request.getParameter("txt1")是否有值,单看你页面的代码,是没有错误的,只有这里可能没有得到值,导致jsp页面是null
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询