Results 1 to 4 of 4
  1. #1
    sarahd19 is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Exclamation reallllllly needs help :(:(:(

    So for my college assignment i've been asked to create a Website with some JSP, i got the login and create a user to work and edit the users details.
    BUT NOW ive hit a problem such a silly one too!!!

    Basically i am creating like a Ticketmaster type website which has users (obv)
    and one administrator this administrator is allowed create the events on this website problem is i wont work ive been struggling with this problem for over a week i need someone elses view on it.

    The Adminstrator creates an event , in turn that gets sent to a createEventEntry.jsp which creates it if all is fine it should go to the displayEvent.jsp which will display the contents i just created easy huh? well i cant seem to fix the problem id be sooooooooooooo grateful to anyone who can help because i cannot move on with the programming until this is fixed!


    User adds in details on form gets sent to this page:

    createEventEntry.jsp

    <%
    EventEntry e;
    Model m;
    String ttl, txt, img;
    int i;



    m = (Model) application.getAttribute("model");
    if (m == null) {
    m = new Model();
    application.setAttribute("model", m);
    }


    ttl = request.getParameter("title");
    txt = request.getParameter("text");
    img = request.getParameter("imageName");

    m.addEventEntry(ttl, txt, img);
    i = m.getNumEntries()-1;
    request.setAttribute("index",new Integer(i));



    %>
    <jsp:forward page="EventsPage.jsp" />

    Which is then forwarded to this

    EventsPage
    <%
    User usr;
    Model m;
    EventEntry e;
    int i;

    i = ((Integer)request.getAttribute("index")).intValue( );


    m = (Model)session.getAttribute("Model");
    usr = (User)session.getAttribute("user");
    e = m.getEventEntry(i);

    %>

    <html>
    <p>
    Entry Date:<%= e.getDateCreated()%>
    </p>
    <p>
    Entry Date:<%= e.getImageName()%>
    </p>
    <br/>
    <p>
    Entry Title:<%= e.getTitle()%>
    </p>
    <br/>
    <p>
    <p>Entry Text:
    <br/>
    <br/>
    <%= e.getText()%>
    </p>
    </html>


    Error Im Getting

    org.apache.jasper.JasperException: An exception occurred processing JSP page /createEventEntry.jsp at line 32

    29:
    30:
    31: %>
    32: <jsp:forward page="EventsPage.jsp" />


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:505)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:398)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)

    root cause

    org.apache.jasper.JasperException: An exception occurred processing JSP page /EventsPage.jsp at line 18

    15:
    16: m = (Model)session.getAttribute("Model");
    17: usr = (User)session.getAttribute("user");
    18: e = m.getEventEntry(i);
    19:
    20: %>
    21: <html>


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:505)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:416)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)
    org.apache.jasper.runtime.PageContextImpl.doForwar d(PageContextImpl.java:696)
    org.apache.jasper.runtime.PageContextImpl.forward( PageContextImpl.java:667)
    org.apache.jsp.createEventEntry_jsp._jspService(cr eateEventEntry_jsp.java:87)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)

    root cause

    java.lang.NullPointerException
    org.apache.jsp.EventsPage_jsp._jspService(EventsPa ge_jsp.java:71)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)
    org.apache.jasper.runtime.PageContextImpl.doForwar d(PageContextImpl.java:696)
    org.apache.jasper.runtime.PageContextImpl.forward( PageContextImpl.java:667)
    org.apache.jsp.createEventEntry_jsp._jspService(cr eateEventEntry_jsp.java:87)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    in this case, it looks like the model attribute is not set on the session attributes, and that is causing the null pointer exception, maybe try:
    Java Code:
    if (m != null) {
      e = m.getEventEntry(i);
    }

  3. #3
    sarahd19 is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    Nope didnt work :/

    i dont understand it , it really should it looks right!

  4. #4
    sarahd19 is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    would i have to go about getting the attributes a different way because its an
    ArrayList it was my first time using them?

    This is my model class that im supposed to be getting the information from:

    package WebAppCA3v2;
    import java.util.*;

    public class Model
    {
    private User[] users;
    private int numUsers;
    private ArrayList<EventEntry> eventEntries = new ArrayList();

    public Model() {
    User u;


    users = new User[ 10000 ];
    numUsers = 0;
    u = addUser("john","john","john@work.ie","secret","dun laoghaire","ireland","D12","123456");
    u.setAdmin(true);

    addEventEntry("My First Event", "My First event", "images/pic4.jpg");
    addEventEntry("My First Event", "My First event", "images/pic3.jpg");
    addEventEntry("My First Event", "My First event", "images/pic2.jpg");

    }


    public User addUser(String uname,String name, String email, String pwd,String add, String ctry,String pc,String tele) {
    User usr;

    usr = new User(uname,name, email, pwd, add, ctry, pc,tele);
    users[ numUsers ] = usr;
    numUsers++;

    return usr;
    }

    public int getNumUsers() { return numUsers; }
    public User getUser(int index) { return users[ index ]; }


    public EventEntry addEventEntry(String ttl, String txt,String img) {
    EventEntry e;

    e = new EventEntry(ttl,txt,img);
    eventEntries.add(e);

    return e;
    }

    public int getNumEntries() { return eventEntries.size(); }
    public EventEntry getEventEntry(int index) { return eventEntries.get(index); }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •