• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Spring mvc annotation

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody

I am writing a controller with annotations and this controller is called by this <href=detail.htm?Sort=’control’>
and it had exception null pointer at "req.getAttribute("Sort").toString();"
this happen because the parm Sort is not passing to the controller.

Somebody can tell me why req.getAttribute("Sort") becames null

Note

Just in case the jsp file "BrowseAdvSearch/ItemList" does not have form.

Thank you.


===================================================================================

public class CopyOfDisplayRowController {

private BrowseClientService userService;
@Autowired // dependency injection using constructor
public CopyOfDisplayRowController(BrowseClientService userService) {
this.userService = userService;
}
@RequestMapping(value="/details.htm")
public String LastName(HttpServletRequest req, HttpServletResponse res, Model model) {


req.getAttribute("Sort").toString(); <<<< Exception (A)

try {
list = userService.getCategories(req,
res,
req.getAttribute("SearchForm").toString(),
req.getAttribute("SearchFirst").toString()
);
} catch (SQLException e) {
try {
doError (req, res, e.getStackTrace(),
" Exception at : com.luque.browse.clients.web.BrowseClients \r\n" +
" :: (Error code : BrowseClients::A0001) \n");
} catch (Exception e1) {
e1.printStackTrace();
}
return null;
}


return "BrowseAdvSearch/ItemList";
}

@RequestMapping("/more.htm")
public String More() {
System.out.println("Remove method called");
return null;
}

@RequestMapping(value = "/previous.htm")
public String Previous() {
System.out.println("Remove method called");
return null;
}

@RequestMapping(value = "/next.htm")
public String Next() {
System.out.println("Remove method called");
return null;
}

public void doError(HttpServletRequest req,
HttpServletResponse res,
StackTraceElement [] stack,
String subject)
throws ServletException, IOException {

req.setAttribute("problem", stack);
req.setAttribute("subject", subject);
RequestDispatcher rd = req.getRequestDispatcher("/project_one/Feedback/ErrorPage02.jsp");
rd.forward(req, res);
}
}

=============================================================================
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, please use code tags while posting to forums, to get more replies.
Problem, lies in using req.getAttribute, you should use request.getParameter not Attribute.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic