java - @WebServlet don't work. getting null value in getAttribute in jsp -


i'm trying set list request attribute print in jsp file. getattrubute in showmentors.jsp giving null value. problem controller or web.xml? please? think controller dose not working.

controller.java

@webservlet("/controller") public class controller extends httpservlet {     private static final long serialversionuid = 1l;     private static sessionfactory factory = null;     //set managers     mentors mentorsmanager = mentors.getinstance();      public static sessionfactory getsessionfactroy() {         try{             if(factory == null)                  factory = new annotationconfiguration().configure().buildsessionfactory();          }         catch(hibernateexception e){             system.err.println(e.getmessage());         }         finally{             return factory;         }     }     /**      * @see httpservlet#httpservlet()      */     public controller() {         super();         // todo auto-generated constructor stub     }     protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {         printwriter out = response.getwriter();//writer of response         string pathbuffer = request.getpathinfo();//the url          switch(pathbuffer){     //switch url          case "/showmentors":             list<mentor> c = mentorsmanager.getallmentors();             request.getsession().setattribute("mymentors", c); // sending coupons view use              request.getservletcontext().getrequestdispatcher("showmentors.jsp").forward(request, response);             break; 

web.xml

  <?xml version="1.0" encoding="utf-8"?> <web-app    version="3.1"    metadata-complete="false"     xmlns="http://xmlns.jcp.org/xml/ns/javaee"    xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"    xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">       <display-name>webperachproject</display-name>     <welcome-file-list>         <welcome-file>index.jsp</welcome-file>     </welcome-file-list>      <servlet>         <servlet-name>controller</servlet-name>         <servlet-class>com.sakhnin.implementations.controller</servlet-class>     </servlet>      <servlet>         <servlet-name>index</servlet-name>         <jsp-file>/jspfiles/index.jsp</jsp-file>     </servlet>     <servlet>         <servlet-name>mentor</servlet-name>         <jsp-file>/jspfiles/mentor.jsp</jsp-file>     </servlet>      <servlet>         <servlet-name>showmentors</servlet-name>         <jsp-file>/jspfiles/showmentors.jsp</jsp-file>     </servlet>       <servlet-mapping>         <servlet-name>index</servlet-name>         <url-pattern>/jspfiles/index.jsp</url-pattern>     </servlet-mapping>     <servlet-mapping>         <servlet-name>showmentors</servlet-name>         <url-pattern>/jspfiles/showmentors.jsp</url-pattern>     </servlet-mapping>     <servlet-mapping>         <servlet-name>mentor</servlet-name>         <url-pattern>/jspfiles/mentors.jsp</url-pattern>     </servlet-mapping>      <servlet-mapping>         <servlet-name>controller</servlet-name>         <url-pattern>/jspfiles/*</url-pattern>     </servlet-mapping>  </web-app> 

showmentors.jsp

  <%@page import="java.util.list"%> <%@ page import="com.sakhnin.classes.*"%> <%@ page import="com.sakhnin.implementations.*"%> <%@ page language="java" contenttype="text/html; charset=windows-1255"     pageencoding="windows-1255"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1255"> <title>all mentors</title> <link type="text/css" rel="stylesheet" href="../stylefile/ourstyle.css" /> <link type="text/css" rel="stylesheet" href="../stylefile/bootstrap.css" /> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" /> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script> </head>  <body>  <div data-role="header" data-theme="b">         <h1>show mentors page</h1>         <div data-role="navbar">             <ul>                 <li><a href="admincontrolpanel" data-icon="home">all mentors </a></li>             </ul>         </div>     </div> <!-- display coupons page -->             <div data-role="content" data-theme="b">             <table class="table table-hover table-striped" id="mentors" height="100%" width="100%" border="3px" bordercolor="blue">                 <thead>                     <tr style="color: green;">                         <th>fullname</th>                     </tr>                 </thead>                 <tbody>                     aaaaaaaaaaaaaaa                          hhhhhhhhhhhhhhhh                         <%                          // retrieves first page , display                          //list<mentor>  m = (list<mentor>)request.getattribute("mymentors");                     list<mentor>  m = (list<mentor>)request.getsession().getattribute("mymentors");                          system.out.println(m);                         %>                         <%                         if (m!=null){                               for(mentor mentor : m) {                     %>                     <td>cccccccccccccccc<br>                         <tr>                             <td><%= mentor.getfullname()%><br>                          </tr>                     <% } }%>                     xxxxxxxxxxxxxxxxxxxxx                 </tbody>             </table>             </div>             <div data-role="footer" data-theme="b">         <h4>by: aseel & rema</h4>     </div> </body> </html> 

first make sure client calling /controller first, not showmentors.jsp

check if mentorsmanager.getallmentors(); returns non-null value, maybe attribute mymentors set correctly, content/value c null;

and suggest if it's request-scope attribute, may pass argument/context using requests context, rather session.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -