Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

error in output

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

index.jsp:

<%@
page language = "java" contentType = "text/html; charset=ISO-8859-1"
pageEncoding = "ISO-8859-1" %>
<!
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix = "s" uri = "/struts-tags" %>
<%@ page import = "java.util.*;" %>
<html>
<head >
<title>Pet Store</title>
</head>
<body>
<h1>Pet Store</h1>
<body>
<h2> Dog</h2>
< s:iterator value = "dogList" var = "dog" > < td >< s:property value = "id" /> <s:property value = "type" /></ td > < td >< s:property value = "age" /></ td > < td >< s:property value = "sex" /></ td > < td >< s:property value = "price" /></ td > < td >< input type = "checkbox" value = "select" ></ td > </s:iterator>
Id Type Age Sex Price Select

</body >
</ html >
struts.xml:
<? xml version = "1.0" encoding = "UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
< struts >
< constant name = "struts.enable.DynamicMethodInvocation" value = "false" />
< constant name = "struts.devMode" value = "false" />
< package name = "default" extends = "struts-default" namespace = "/" >
< action name = "display"
class = "com.petstore.view.PetStoreAction" >
< result name = "success" > index.jsp </ result >
</action>
</package>
</struts >

web.xml:
<? xml version = "1.0" encoding = "UTF-8" ?>
<web-app xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = xmlns:web = xsi:schemaLocation = id = "WebApp_ID" version = "2.5" >
<display-name>Struts2 Application</display-name>
<filter>
<filter-name>struts2</filter-name>
<!-- <filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class> -->
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list >
</web-app>

PetManger.java:
package com.petstore.controller;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import com.petstore.model.Dog;
import com.petstore.util.HibernateUtil;

public class PetManager extends HibernateUtil {
public List<Dog> getDogList() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List<Dog> dogList = null;
try {
dogList = (List<Dog>)session.createQuery("from Dog").list();
} catch (HibernateException e) {
e.printStackTrace();
session.getTransaction().rollback();
}
session.getTransaction().commit();
return dogList;
}
}
PetStoreAction.java:
package com.petstore.view;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.petstore.model.Dog;
import com.petstore.controller.PetManager;
public class PetStoreAction extends ActionSupport {
private Dog dog;
private List<Dog> dogList;
private Long id;
private PetManager manager;
public PetStoreAction() {
manager = new PetManager();
}
public String execute() {
this.dogList = manager.getDogList();
return SUCCESS;
}
public String display (){
this.dogList = manager.getDogList();
return SUCCESS;
}
}
Dog.java:

package com.petstore.model;
public class Dog {
privateint id ;
private String type ;
private String sex ;
privatelong price ;
privateint age ;
Dog (){}
publicvoid setId( int i){
this . id =i;
}
publicint getid(){
return id ;
}
publicvoid setType(String dogType){
this . type = dogType;
}
public String getType(){
return type ;
}
publicvoid setSex( String dogSex){
this . sex = dogSex;
}
public String getSex(){
return sex ;
}
publicvoid setPrice( long dogPrice){
this . price = dogPrice;
}
publiclong getPrice(){
return price ;
}
publicvoid setAge( int dogAge){
this . age = dogAge;
}
publicint getAge(){
return age ;
}
}


HibernateUtil.java:

package com.petstore.util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new AnnotationConfiguration().configure()
.buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}





Hi I am new to struts. I am trying to display records from DOG table. But the output displays only web page. No error is shwon.

Any help would be appreciated.

thanks
Sailaja







 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic