JSP and Spring FrameWork

SQL statement for testing


Check SQL Statements
Code

Functions

  • login and register
user admin
view course announcement add and view course announcement
view quiz add and view quiz
--- add course aim

Problem Solving

CSS and JS file setting


Problem shooting: After apply web application to spring framework, all the css and js file were disabled.

  • Apply online css and js style elements from BootStrap.


...
JSP and Spring FrameWork_第1张图片
after_apply_css_js.png

Set Admin permission


Problem shooting: When we apply the if-else statement in Controller class, the boolean result is return null. Null pointer Exception occur, The application will **skip checking **admin value.
-> the result page will random direct to admin or student.

  • Mindmap
JSP and Spring FrameWork_第2张图片
Filter_roadmap.png
  • in web.xml Matching "/course/*" to access AuthenticationFilter
    
        authFilter
        edu.ouhk.comps380f.lab8exercises.AuthenticationFilter
    
    
        authFilter
        /course
        /course/*
    
  • Apply filter function in AuthenticationFilter
@Override
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) throws IOException, ServletException
    {
        //...check user name and password validation..
            if(session.getAttribute("admin") == Boolean.FALSE)
            {
                ((HttpServletResponse)response).sendRedirect(
                    ((HttpServletRequest) request).getContextPath() + "/student"
                );
            }
            chain.doFilter(request, response);
        }
    }

@Autowire Exception


Cannot use @Autowired and implement at the same time.
-> cannot apply @Autowired exception will occur

public class AnnouncementDaoImpl implements AnnouncementDao {
    ...
    @Autowired
    Announcenment announcenment;

    @Override
    public List getAllAnnouncement(){
        List x = new ArrayList<>();
        //...sql get all list statement
        return x;
    }
}
  • Delete below @Autowired
@Autowired
    Announcenment announcenment;

Database Size

Problem shooting: If the sql VARCHAR(255) number too large then the url cannot return String it will return
http://localhost:8080/Lab8Exercises/doquiz?title=Q1%0121
->Q1%0121 cannot match database data.

  • Drop table and set all VARCHAR(50)

Page Forward cause losing url package error

Problem Shooting: you need you manually add this/Lab8Exercises/ in the middle of url.
Error log: No mapping found for HTTP request with URI [/Lab8Exercises/course/doquiz] in DispatcherServlet

  • MindMap
JSP and Spring FrameWork_第3张图片
mindmapPathDirectory.png
  • Try use

  • Student.jsp


     

${entry.title}

//or

${entry.title}

  • CourseController.java
...
    private List quizs = new ArrayList<>(); 
...

    @RequestMapping(value = "/doquiz")
    public ModelAndView doQuiz( HttpSession session,
                                HttpServletRequest request,
                                ModelMap model1, 
                                @RequestParam ("title") String title) {

      //sudo code:
      //titleValue = Get title String value
      //Use titleValue as key get other value form quiz table
      //-> quizDao.getSingleQuizValue(titleValue);
      return new ModelAndView("/doquiz");
    }
...

File upload


Problem shooting: Don't know how to do upload image,pdf to database using javaServlet page.

Reference


[1]Spring tutorial

[2]formal tutorial

[3]Spring io

[4]Spring template database example:

[5]Quiz HTML form

你可能感兴趣的:(JSP and Spring FrameWork)