问题描述
- 怎么将后台内容显示在jsp页面上?
-
报得错误是:
NoSuchMethodException: com.krt.person.action.personAction.select()
java.lang.Class.getMethod(Class.java:1605)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:75)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:47)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:139)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:562)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)代码如下: public class person_entity_dao { //连接数据库 public Connection connectionDB() throws Exception{ String url="jdbc:mysql://localhost:3306/test"; Connection conn=null; try{ Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection(url, "root", "123456"); } catch(ClassNotFoundException e){ System.out.println("驱动失败"); } catch(SQLException e){ System.out.println("连接数据库失败"); } return conn; } public List quaryList(String name,String age,String sex){ //构造map集合 Map map= new HashMap(); //定义一个元素数据并赋初值 ResultSetMetaData md=null; //构造一个数组列表 List listofRows =new ArrayList(); try { Connection conn=this.connectionDB(); String select="select * from tb_user where name='"+name+"' and age='"+age+"' and sex='"+sex+"'"; System.out.println(select); PreparedStatement ps=conn.prepareStatement(select); //获得结果集 ResultSet rs=ps.executeQuery(); //获得数据集 md=rs.getMetaData(); //获得数据集中列的总数 int num=md.getColumnCount(); //读取数据 while (rs.next()){ //构造一个LinkedHashMap存储数据 LinkedHashMap mapofvalues =new LinkedHashMap(); for(int i=1;i<num;i++){ mapofvalues.put(md.getColumnName(i), rs.getObject(i)); } //将mapofvalues添加到listofRows中 listofRows.add(mapofvalues); } } catch (Exception e) { e.printStackTrace(); } return listofRows; }
}
public List quaryList(String name, String age,String sex){ return dao.quaryList(name, age, sex); } public String select(ServletRequest Request) throws Exception{ String name=ServletActionContext.getRequest().getParameter("name"); String age=ServletActionContext.getRequest().getParameter("age"); String sex=ServletActionContext.getRequest().getParameter("sex"); List listofRows= service.quaryList(name, age, sex); System.out.println(listofRows.toString()); ((ServletRequest) Request).setAttribute("listofRows", listofRows ); ActionContext.getContext().getSession().put("listofRows",listofRows); //双向搜索接口 Iterator its=listofRows.iterator(); while( its.next()!= null){ return "ok"; } return "error"; } } jsp文件: </head>
编号 姓名 年龄 性别 入职时间 联系电话 职位号 部门号 用户名 密码 <% List listofRows =(List)request.getAttribute("listofRows");
if(listofRows.size()!=0){ for(int i=0;i<listofRows.size();i++){ pageContext.setAttribute("listofRows",listofRows.get(i)); } }
%>
<tr> <td>${listofRows.id}</td> <td>${listofRows.name}</td> <td>${listofRows.age}</td> <td>${listofRows.sex}</td> <td>${listofRows.time}</td> <td>${listofRows.telphone}</td> <td>${listofRows.rid}</td> <td>${listofRows.did}</td> <td>${listofRows.username}</td> <td>${listofRows.password}</td> </tr> </table>
解决方案
如何在限制页面中显示的内容的字数?
关于后台读取数据显示到页面
页面元素中内容显示在最上面
解决方案二:
NoSuchMethodException: 找不到后台方法
时间: 2025-01-20 17:01:47