java - I cannot acces modelmap values in my JSP page -
i refactoring code , ended deleting bean altogether. modelmap values getting passed correctly , displayed on jsp page presence of bean. however, pulling info straight database, cannot access values on jsp page though info getting read correctly.
i have like:-
public string viewdata(@modelattribute("") modelmap model) { connection conn = null; resultset rs = null; string driver = "com.mysql.jdbc.driver"; statement statement = null; try{ class.forname(driver); conn = drivermanager.getconnection("jdbc:mysql://localhost:3306/testing1234","root","root"); statement = conn.createstatement(); string sql = "select * testdata"; rs = statement.executequery(sql); while (rs.next()) { model.addattribute("test", rs.getstring(1)); model.addattribute("test1", rs.getstring(2)); model.addattribute("test2", rs.getstring(3)); model.addattribute("test3", rs.getstring(4)); model.addattribute("test4" ,rs.getdate(5)); } } grab (sqlexception e) { e.printstacktrace(); } grab (classnotfoundexception e) { e.printstacktrace(); }finally { seek { if (rs != null) { rs.close(); } if (statement != null) { statement.close(); } if (conn!= null) { conn.close(); } } grab (sqlexception e) { e.printstacktrace(); } } homecoming "jsppage"; }
however, in jsp page when seek accessing ${test}, empty string. there alternate way around this, can display info on jsp page?
spring handles handler method arguments handlermethodargumentresolver
interface. implementation handles @modelattribute
, servletmodelattributemethodprocessor
, has higher priority (is registered before) implementation handles modelmap
, mapmethodprocessor
.
what means spring create modelmap
object , set model
key ""
. can access attribute empty key jsp , access elements through (the nested attributes add together resultset
).
the best solution imo rid of @modelattribute
annotation method parameter.
java jsp spring-mvc
No comments:
Post a Comment