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.
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
...
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
Filter_roadmap.png
  • in web.xml Matching "/course/*" to access AuthenticationFilter
    <filter>
        <filter-name>authFilter</filter-name>
        <filter-class>edu.ouhk.comps380f.lab8exercises.AuthenticationFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>authFilter</filter-name>
        <url-pattern>/course</url-pattern>
        <url-pattern>/course/*</url-pattern>
    </filter-mapping>
  • 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<Announcenment> getAllAnnouncement(){
        List<Announcenment> 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
mindmapPathDirectory.png
  • Try use <c:url ...

  • Student.jsp

<c:forEach varStatus= "loop" items="${quizs}" var ="entry">
     <h3><a href="/course/doquiz?title=${entry.title}"> ${entry.title}</a></h3>
//or <h3><a href="/LabExercises/course/doquiz?title=${entry.title}"> ${entry.title}</a></h3>
</c:forEach>
  • CourseController.java
...
    private List<Quiz> 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容