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" >
...
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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末肯污,一起剝皮案震驚了整個(gè)濱河市榛鼎,隨后出現(xiàn)的幾起案子啦桌,更是在濱河造成了極大的恐慌城看,老刑警劉巖柏副,帶你破解...
    沈念sama閱讀 219,366評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)括改,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,521評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)家坎,“玉大人嘱能,你說(shuō)我怎么就攤上這事∈瑁” “怎么了惹骂?”我有些...
    開封第一講書人閱讀 165,689評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)做瞪。 經(jīng)常有香客問(wèn)我对粪,道長(zhǎng),這世上最難降的妖魔是什么装蓬? 我笑而不...
    開封第一講書人閱讀 58,925評(píng)論 1 295
  • 正文 為了忘掉前任衩侥,我火速辦了婚禮,結(jié)果婚禮上矛物,老公的妹妹穿的比我還像新娘茫死。我一直安慰自己,他們只是感情好履羞,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,942評(píng)論 6 392
  • 文/花漫 我一把揭開白布峦萎。 她就那樣靜靜地躺著,像睡著了一般忆首。 火紅的嫁衣襯著肌膚如雪爱榔。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,727評(píng)論 1 305
  • 那天糙及,我揣著相機(jī)與錄音详幽,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛唇聘,可吹牛的內(nèi)容都是我干的版姑。 我是一名探鬼主播,決...
    沈念sama閱讀 40,447評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼迟郎,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼剥险!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起宪肖,我...
    開封第一講書人閱讀 39,349評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤表制,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后控乾,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體么介,經(jīng)...
    沈念sama閱讀 45,820評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,990評(píng)論 3 337
  • 正文 我和宋清朗相戀三年蜕衡,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了夭拌。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,127評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡衷咽,死狀恐怖鸽扁,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情镶骗,我是刑警寧澤桶现,帶...
    沈念sama閱讀 35,812評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站鼎姊,受9級(jí)特大地震影響骡和,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜相寇,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,471評(píng)論 3 331
  • 文/蒙蒙 一慰于、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧唤衫,春花似錦婆赠、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,017評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至赃承,卻和暖如春妙黍,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背瞧剖。 一陣腳步聲響...
    開封第一講書人閱讀 33,142評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工拭嫁, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留可免,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,388評(píng)論 3 373
  • 正文 我出身青樓做粤,卻偏偏與公主長(zhǎng)得像浇借,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子驮宴,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,066評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容