0

When I'm trying to execute my app in tomcat i get following error:

"The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."

Can someone help me with finding solution?

I used existing cofinguration, which worked for another person, searched project many times, but haven't find issue.

Controller

@Controller
public class BookController {

@Autowired
private BookService bookService;

@RequestMapping ("/index")
public String setupForm (Map<String, Object> map) {
    Book book = new Book();
    map.put("book", book);
    map.put("bookList", bookService.getAllBook());
    return "book";
}
@RequestMapping (value = "/book.do", method = RequestMethod.POST)
public String doActions(@ModelAttribute Book book, BindingResult result, @RequestParam String action, Map<String, Object> map) {
    Book bookResult = new Book();
    switch(action.toLowerCase()) {
    case "add":
        bookService.add(book);
        bookResult = book;
    break;

    case "edit":
        bookService.edit(book);
        bookResult = book;
    break;

    case "delete":
        bookService.delete(book.getBookId());
        bookResult = new Book();
    break;

    case "search":
        Book searchedBook = bookService.getBook(book.getBookId());
        bookResult = searchedBook;
    break;
    }

    map.put("book", bookResult);
    map.put("bookList", bookService.getAllBook());
    return "book";

  }
}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SpringHibernateSql</groupId>
<artifactId>SpringHibernateSql</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
<org.springframework.version>5.0.0.RELEASE</org.springframework.version>        
</properties>

<dependencies>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${org.springframework.version}</version>
</dependency>

<!-- Hibernate resources -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.6.7.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>4.3.0.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-commons-annotations</artifactId>
    <version>3.3.0.ga</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-annotations</artifactId>
    <version>3.3.1.GA</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>3.3.2.GA</version>
</dependency>
<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.1.2</version>
</dependency>
<dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>20030825.184428</version>
</dependency>
<dependency>
    <groupId>commons-pool</groupId>
    <artifactId>commons-pool</artifactId>
    <version>20030825.183949</version>
</dependency>
<!-- MySQL -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.6</version>
</dependency>
<!-- Log4j -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.14</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency>
</dependencies>


<build>
<testSourceDirectory>src/main/test</testSourceDirectory>
<resources>
  <resource>
    <directory>src/main/resources</directory>
    <excludes>
      <exclude>**/*.java</exclude>
    </excludes>
  </resource>
  <resource>
    <directory>src/main/webapp</directory>
    <excludes>
      <exclude>**/*.java</exclude>
    </excludes>
  </resource>
</resources>
<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
    </configuration>
  </plugin>
  </plugins>
  </build>
 </project>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" 
version="3.0">
<display-name>SpringHibernateSql</display-name>

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.xml</param-value>
</context-param>
<listener>
    <listener-
class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-
class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/includes.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Book Management</title>
</head>
<body>
<h1>Book data</h1>
<form:form action = "book.do" method = "POST" commandName = "book">
<table>
    <tr>
        <td>Book ID</td>
        <td><form:input path="bookId" /></td>
    </tr>
    <tr>
        <td>Title</td>
        <td><form:input path="title" /></td>
    </tr>
    <tr>
        <td>Description</td>
        <td><form:input path="description" /></td>
    </tr>
    <tr>
        <td colspan = "2">
            <input type = "submit" name = "action" value = "Add" />
            <input type = "submit" name = "action" value = "Edit" />
            <input type = "submit" name = "action" value = "Delete" />
            <input type = "submit" name = "action" value = "Search" />
    </tr>
</table>
</form:form>
<br>
<table border = "1">
<th>ID</th>
<th>Title</th>
<th>Description</th>
<c:forEach items = "${bookList}" var = "book">
    <tr>
        <td>${book.bookId}</td>
        <td>${book.title}</td>
        <td>${book.description}</td>
    </tr>
 </c:forEach>
 </table>
 </body>
 </html>
D.Wasilewski
  • 119
  • 3
  • 3
  • 12
  • ... and jsp part is for index.jsp? What is the request? If it is failing at start, then can you follow any tutorial, like this one : http://www.tutorialspoint.com/articles/run-your-first-jsp-program-in-apache-tomcat-server - that is faster way, less guessing. It can be that your war is not installed, or it is installed, but you need folder prefix in your URL, and probably tons of other problems that did not popped up in my mind. – Michał Zaborowski Oct 24 '17 at 18:24
  • Possible duplicate of [Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"](https://stackoverflow.com/questions/11731377/servlet-returns-http-status-404-the-requested-resource-servlet-is-not-availa) – juanlumn Oct 24 '17 at 18:41
  • I changed mapping to ("/book"), which is name of my jsp, however it didn't fix the problem. I also moved folder with jsps to webapp folder, instead of WEB-INF, still not helped. How can i check if my war is intalled? @MichałZaborowski – D.Wasilewski Oct 24 '17 at 19:16
  • @juanlumn - that is not exact duplicate, since here web.xml is used. @D.Wasilewski - tomcat has something like web-apps, and your app should be there. Also, your servlet is named `spring`. Please provide URL that fails... – Michał Zaborowski Oct 25 '17 at 05:48

0 Answers0