SQL statement for testing
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">
...
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
- 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
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
[3]Spring io