2016-04-28 23 views
0

Springを使用してレコードを検索し、JSPで表示しようとしています。 ブラウザで以下のエラーに直面しています。Spring JDBCを使用してレコードを取得する方法

例外メッセージ: page

私のJSP: Search.jsp:

<div class="container"> 
 
    <div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3"> 
 
     <div class="row"> 
 
      <div class="col-xs-12 col-sm-6 col-md-6"> 
 
       <div class="form-group"> 
 
        <form action="/SpringMail/searchresults" method="get"> 
 
         <input type="text" name="searchRecord" id="search_record" class="form-control input-lg" placeholder="Enter email to search" tabindex="1" required="required"> 
 
         <div class="col-xs-12 col-md-6"><input type="submit" value="Search" class="btn btn-primary btn-block btn-lg search" tabindex="4"></div> 
 
        </form> 
 
       </div> 
 
      </div> 
 
     </div> 
 
    </div> 
 
</div>

Searchresult.jsp:それはテーブルを持っています。だから私はそのコードを含んでいるだけです。

<table class="table"> 
 
    <thead> 
 
     <tr> 
 
      <th>#</th> 
 
      <th>Firstname</th> 
 
      <th>Lastname</th> 
 
      <th>DisplayName</th> 
 
      <th>DateOfBirth</th> 
 
      <th>Email</th> 
 
      <th>Password</th> 
 
    \t  <th>Contact</th> 
 
    \t  <th>Skills</th> 
 
     </tr> 
 
    </thead> 
 
    <tbody> 
 
    <% 
 
     List students = (List)request.getAttribute("searchresult"); 
 
     Iterator stdIter = students.iterator(); 
 
     
 
     while(stdIter.hasNext()) { 
 
      Student s = (Student) stdIter.next(); 
 
    %> 
 
     <tr> 
 
      <td><% s.getFirstName(); %></td> 
 
      <td><% s.getLastName(); %></td> 
 
      <td><% s.getDisplayName(); %></td> 
 
      <td><% s.getDateOfBirth(); %></td> 
 
      <td><% s.getEmail(); %></td> 
 
      <td><% s.getPassword(); %></td> 
 
      <td><% s.getContact(); %></td> 
 
      <td><% s.getStudentSkills(); %></td> 
 
     </tr> 
 
    <% } %> 
 
    </tbody> 
 
</table>

マイコントローラー:RegistrationController:

` // For Search 
@RequestMapping(value="/search", method=RequestMethod.GET) 
public ModelAndView getSearchForm() { 
    ModelAndView searchmv = new ModelAndView("search"); 
    return searchmv; 
} 

@RequestMapping(value="/searchresults/{email}", method=RequestMethod.GET) 
public ModelAndView searchResults(@PathVariable("email") String email,HttpServletRequest request) { 
    System.out.println("Inside Search method"); 
    ModelAndView searchResult = new ModelAndView("searchresult"); 
    request.setAttribute("searchresult", st.getStudent(email)); 
    return searchResult; 
} 
// For Search` 

getStudent(): 


    public List<Student> getStudent(String email) { 
    System.out.println("Inside getStudent() method"); 
    System.out.println("Entered email: " + email); 
    List studentList = new ArrayList(); 
    String sql = "select * from student where email = " + email; 
    studentList = jt.query(sql, new StudentRowMapper()); 
    return studentList; 
} 

私はこれをやっているが初めてで渡します。親切に私にそれを行う正しい方法を案内します。

+0

私が正しくsearch.jspを取得していますため

@RequestMapping(value="/searchresults", method=RequestMethod.GET) public ModelAndView searchResults(@RequestParam("searchRecord") String email, Map model) { ModelAndView searchResult = new ModelAndView("searchresult"); model.put("searchresult", st.getStudent(email)); return searchResult; } 

感謝。しかし、私はenterをクリックした後に404になっています。 – Bobby

+0

404は、ページがサーバー上に存在しないことを意味します。リクエストURLを確認してください。 – Pras

+0

おそらく、 'ViewResolver'はあなたのJSPファイルを見つけることができません。それらが 'ModelAnd'View'で使用しているのとまったく同じ名前で、それらが適切な場所にあることを確認してください。 –

答えて

0

私は答えを得た。 メソッド:RegistrationControllerのsearchResultsの形式が間違っています。 このように修正しました。私が検索し、DBから同じレコードを取得するために、ページ内の電子メールを与える入力

関連する問題