Hi,
I am learning Struts2 and developed an website called BookShop; In add book section after i clicked on save button without entering any values for the mandatory fields it should return the same
jsp page(addBooks.jsp) after validating the fields but it gives a HTTP Status 404 - /BookShop
/JSP/JSP/addBooks.jsp
By looking at the above path, we can say it does validates but not giving back the correct path. I dont know how JSP appeared twice here. I have only one JSP folder under BookShop Project.
Please find the below code:
Struts.xml (please find the code in red color):
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : struts.xml
Created on : 13 November, 2011, 1:40 PM
Author : Nagaraj S K
Description:
Purpose of the document follows.
-->
<!DOCTYPE
struts PUBLIC '-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN' 'http://struts.apache.org/dtds/struts-2.0.dtd'>
<struts>
<package name="bookshop" extends="struts-default">
<interceptors>
<interceptor name="loginInterceptor" class="bookShop.AuthenticationInterceptor"/>
<interceptor-stack name="myStack">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="loginInterceptor"/>
</interceptor-stack>
</interceptors>
<global-results>
<result name="loginAction" type="redirect-action">index</result>
</global-results>
<action name="index">
<result>JSP/login.jsp</result>
</action>
<action name="doLogin" class="bookShop.loginAction">
<result name="success" type="redirect-action">showSearchBooks</result>
<result name="error">JSP/login.jsp</result>
<result name="input">JSP/login.jsp</result>
</action>
<action name="showSearchBooks">
<interceptor-ref name="myStack"/>
<result>JSP/searchBooks.jsp</result>
</action>
<action name="doSearchBooks" class="bookShop.searchBooksAction">
<interceptor-ref name="myStack"/>
<result name="success">JSP/searchBooks.jsp</result>
<result name="input">JSP/searchBooks.jsp</result>
</action>
<action name="doInsertBooks" class="bookShop.insertBooksAction">
<interceptor-ref name="myStack"/>
<result name="success">JSP/manageBooks.jsp</result>
<result name="input">JSP/addBooks.jsp</result>
</action>
<action name="doDeleteBooks" class="bookShop.deleteBookAction">
<interceptor-ref name="myStack"></interceptor-ref>
<result name="success">JSP/manageBooks.jsp</result>
</action>
<action name="doLogout" class="bookShop.logOffAction">
<result type="redirect-action">index</result>
</action>
<action name="showManageBooks">
<interceptor-ref name="myStack" />
<result>JSP/manageBooks.jsp</result>
</action>
<action name="showAddBooks">
<interceptor-ref name="myStack" />
<result type="redirect">JSP/addBooks.jsp</result>
</action>
<action name="showEditBooks" class="bookShop.editBookAction">
<interceptor-ref name="myStack" />
<result name="success">JSP/updateBooks.jsp</result>
</action>
<action name="doUpdateBooks" class="bookShop.updateBookAction">
<interceptor-ref name="myStack" />
<result name="success">JSP/manageBooks.jsp</result>
<result name="input">JSP/updateBooks.jsp</result>
</action>
<action name="doManageSearchBooks" class="bookShop.manageSearchBooksAction">
<interceptor-ref name="myStack" />
<result name="success">JSP/manageBooks.jsp</result>
</action>
</package>
</struts>
addBooks.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!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>BookShop[Sharanam & Vaishali Shah] - Add Books</title>
<link href="/BookShop/css/stylesheet.css" type="text/css" rel="stylesheet">
<s:head />
</head>
<body>
<s:include value="menu.jsp" />
<s:form id="frmBooks" name="frmBooks" action="doInsertBooks" method="post">
<table border="0" >
<tr>
<td>
<table BORDER="0" >
<tr>
<td >
Add Books
</td>
<td class="treb13blacknormal" >
It is mandatory to enter information in all information
capture boxes which have a <span class="mandatory">*</span> adjacent
</td>
</tr>
</table>
</td>
</tr>
<tr >
<td >
</td>
</tr>
<tr >
<td>
<table border="0" >
<tr>
<td>
<table border="0" >
<tr>
<td class="Arial13BrownB">
Book Details
</td>
</tr>
<s:textfield required="true" requiredposition="left" id="BookName" label="Book" name="BookName" title="Enter the book name" maxLength="25" size="55"/>
<s:textfield required="true" requiredposition="left" id="PublisherName" label="Publisher" name="PublisherName" title="Enter the publisher name" maxLength="25" size="55"/>
<s:textfield required="true" requiredposition="left" id="Category" label="Category" name="Category" title="Enter the category name" maxLength="25" size="55"/>
<s:textfield required="true" requiredposition="left" id="ISBN" label="ISBN" name="ISBN" title="Enter the ISBN" maxLength="15" size="30"/>
<s:textfield required="true" requiredposition="left" id="Edition" label="Edition" name="Edition" title="Enter the edition of the book" maxLength="25" size="55"/>
<s:textfield required="true" requiredposition="left" id="Year" label="Year" name="Year" title="Enter the year" maxLength="4" size="4"/>
<s:textfield required="true" requiredposition="left" id="Cost" label="Cost" name="Cost" title="Enter the cost of the book" maxLength="8" size="8"/>
<tr>
<td class="Arial13BrownB">
Author Details
</td>
</tr>
<s:textfield required="true" requiredposition="left" id="FirstAuthor" label="First Author" name="FirstAuthor" title="Enter the name of the author" maxLength="25" size="55"/>
<s:textfield id="SecondAuthor" label="Second Author" name="SecondAuthor" title="Enter the name of the author" maxLength="25" size="55"/>
<s:textfield id="ThirdAuthor" label="Third Author" name="ThirdAuthor" title="Enter the name of the author" maxLength="25" size="55"/>
<s:textfield id="FourthAuthor" label="Fourth Author" name="FourthAuthor" title="Enter the name of the author" maxLength="25" size="55"/>
<tr>
<td class="Arial13BrownB">
Description
</td>
</tr>
<s:textarea required="true" requiredposition="left" id="Synopsis" label="Synopsis" name="Synopsis" title="Enter the synopsis" cols="80" rows="5"></s:textarea>
<s:textarea required="true" requiredposition="left" id="AboutAuthors" label="About Authors" name="AboutAuthors" title="Enter the about author details" cols="80" rows="5"></s:textarea>
<s:textarea id="TopicsCovered" label="Topics Covered" name="TopicsCovered" title="Enter the topics covered in the book" cols="80" rows="5"></s:textarea>
<s:textarea id="ContentsCDROM" label="Contents Of CDROM" name="ContentsCDROM" title="Enter the contents of CDROM" cols="80" rows="5"></s:textarea>
</table>
</td>
</tr>
<tr>
<td>
<s:submit theme="simple" cssStyle="background:url(/BookShop/images/submit_bg.gif) no-repeat scroll 37px 0px;" cssClass="buttonText" name="btnSubmit" id="btnSubmit" value="Save" />
<s:reset theme="simple" cssStyle="background:url(/BookShop/images/submit_bg.gif) no-repeat scroll 37px 0px;" cssClass="buttonText" name="btnReset" id="btnReset" value="Clear" />
</td>
</tr>
</table>
</td>
</tr>
<tr >
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</s:form>
</body>
</html>
inserBooksAction-validation.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC '-//OpenSymphony Group//XWork Validator 1.0.2//EN' 'http://www.opensymphony.com/xwork-validator-1.0.2.dtd'>
<validators>
<field name="BookName">
<field-validator type="requiredstring">
<message>Please enter the book name.</message>
</field-validator>
</field>
<field name="PublisherName">
<field-validator type="requiredstring">
<message>Please enter the publisher name.</message>
</field-validator>
</field>
<field name="Category">
<field-validator type="requiredstring">
<message>Please enter the category name.</message>
</field-validator>
</field>
<field name="ISBN">
<field-validator type="requiredstring">
<message>Please enter the book ISBN.</message>
</field-validator>
</field>
<field name="Edition">
<field-validator type="requiredstring">
<message>Please enter the edition of the book.</message>
</field-validator>
</field>
<field name="Year">
<field-validator type="required" short-circuit="true">
<message>Please enter the year when the book was published.</message>
</field-validator>
<field-validator type="int" short-circuit="true">
<message>Enter a numeric value</message>
</field-validator>
</field>
<field name="Cost">
<field-validator type="required" short-circuit="true">
<message>Please enter the cost of the book.</message>
</field-validator>
<field-validator type="int" short-circuit="true">
<message>Enter a numeric value</message>
</field-validator>
</field>
<field name="FirstAuthor">
<field-validator type="requiredstring">
<message>Please enter the name of the first author.</message>
</field-validator>
</field>
<field name="Synopsis">
<field-validator type="requiredstring">
<message>Please enter the synopsis of the book.</message>
</field-validator>
</field>
<field name="AboutAuthors">
<field-validator type="requiredstring">
<message>Please enter the about the author details.</message>
</field-validator>
</field>
</validators>
Can you please help me to solve this?
Thanks in advance
Nagaraj