aspose file tools*
The moose likes Struts and the fly likes Jsp is not displaying in Struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Jsp is not displaying in Struts2" Watch "Jsp is not displaying in Struts2" New topic
Author

Jsp is not displaying in Struts2

Nagaraj Shivaklara
Ranch Hand

Joined: Dec 16, 2008
Posts: 75
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




Thanks n Regards,
Nagaraj S K
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

Define namespace in package.

<package name="bookshop" extends="struts-default" namespace="/JSP">

And modify result types like this

<result name="success">/manageBooks.jsp</result>
<result name="input">/addBooks.jsp</result>


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
Nagaraj Shivaklara
Ranch Hand

Joined: Dec 16, 2008
Posts: 75
Hi Mohana,

I have modified as you said, but when i run the application i am getting the below error also find the below struts.xml:
20 Nov, 2011 8:46:47 AM org.apache.struts2.dispatcher.Dispatcher serviceAction
SEVERE: Could not find action or result
There is no Action mapped for namespace / and action name index. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)



Struts.xml:

<?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" namespace="/JSP">
<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>/login.jsp</result>
</action>

<action name="doLogin" class="bookShop.loginAction">
<result name="success" type="redirect-action">showSearchBooks</result>
<result name="error">/login.jsp</result>
<result name="input">/login.jsp</result>
</action>

<action name="showSearchBooks">
<interceptor-ref name="myStack"/>
<result>/searchBooks.jsp</result>
</action>

<action name="doSearchBooks" class="bookShop.searchBooksAction">
<interceptor-ref name="myStack"/>
<result name="success">/searchBooks.jsp</result>
<result name="input">/searchBooks.jsp</result>
</action>


<action name="doInsertBooks" class="bookShop.insertBooksAction">
<interceptor-ref name="myStack"/>
<result name="success">/manageBooks.jsp</result>
<result name="input">/addBooks.jsp</result>
</action>
<action name="doDeleteBooks" class="bookShop.deleteBookAction">
<interceptor-ref name="myStack"></interceptor-ref>
<result name="success">/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>/manageBooks.jsp</result>
</action>

<action name="showAddBooks">
<interceptor-ref name="myStack" />
<result type="redirect">/addBooks.jsp</result>
</action>

<action name="showEditBooks" class="bookShop.editBookAction">
<interceptor-ref name="myStack" />
<result name="success">/updateBooks.jsp</result>
</action>

<action name="doUpdateBooks" class="bookShop.updateBookAction">
<interceptor-ref name="myStack" />
<result name="success">/manageBooks.jsp</result>
<result name="input">/updateBooks.jsp</result>
</action>

<action name="doManageSearchBooks" class="bookShop.manageSearchBooksAction">
<interceptor-ref name="myStack" />
<result name="success">/manageBooks.jsp</result>
</action>

</package>
</struts>


Mohana Rao wrote:Define namespace in package.

<package name="bookshop" extends="struts-default" namespace="/JSP">

And modify result types like this

<result name="success">/manageBooks.jsp</result>
<result name="input">/addBooks.jsp</result>
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

what is the url it's producing when you are getting that error message.

http://localhost:portnumber/projectName/JSP/youractionname what you are trying to execute.
Nagaraj Shivaklara
Ranch Hand

Joined: Dec 16, 2008
Posts: 75
URL is : http://localhost:8084/BookShop/index.action

In the webpage its displaying as below:

HTTP Status 404 - There is no Action mapped for namespace / and action name index.

type Status report

message There is no Action mapped for namespace / and action name index.

description The requested resource (There is no Action mapped for namespace / and action name index.) is not available.

Apache Tomcat/6.0.18


Mohana Rao wrote:what is the url it's producing when you are getting that error message.
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

Then do one thing make the namespace as / instead of "/JSP".

Surely, you are facing problem with namespace.

http://struts.apache.org/2.0.14/docs/namespace-configuration.html

Nagaraj Shivaklara
Ranch Hand

Joined: Dec 16, 2008
Posts: 75
Hi Mohana,

After modifying also i am still getting below error( also please find the below modified struts.xml):

URL: http://localhost:8084/BookShop/index.action

HTTP Status 404 - /BookShop/login.jsp

--------------------------------------------------------------------------------

type Status report

message /BookShop/login.jsp

description The requested resource (/BookShop/login.jsp) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.18

Struts.xml:

<?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" namespace="/">
<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>/login.jsp</result>
</action>

<action name="doLogin" class="bookShop.loginAction">
<result name="success" type="redirect-action">showSearchBooks</result>
<result name="error">/login.jsp</result>
<result name="input">/login.jsp</result>
</action>

<action name="showSearchBooks">
<interceptor-ref name="myStack"/>
<result>/searchBooks.jsp</result>
</action>

<action name="doSearchBooks" class="bookShop.searchBooksAction">
<interceptor-ref name="myStack"/>
<result name="success">/searchBooks.jsp</result>
<result name="input">/searchBooks.jsp</result>
</action>


<action name="doInsertBooks" class="bookShop.insertBooksAction">
<interceptor-ref name="myStack"/>
<result name="success">/manageBooks.jsp</result>
<result name="input">/addBooks.jsp</result>
</action>
<action name="doDeleteBooks" class="bookShop.deleteBookAction">
<interceptor-ref name="myStack"></interceptor-ref>
<result name="success">/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>/manageBooks.jsp</result>
</action>

<action name="showAddBooks">
<interceptor-ref name="myStack" />
<result type="redirect">/addBooks.jsp</result>
</action>

<action name="showEditBooks" class="bookShop.editBookAction">
<interceptor-ref name="myStack" />
<result name="success">/updateBooks.jsp</result>
</action>

<action name="doUpdateBooks" class="bookShop.updateBookAction">
<interceptor-ref name="myStack" />
<result name="success">/manageBooks.jsp</result>
<result name="input">/updateBooks.jsp</result>
</action>

<action name="doManageSearchBooks" class="bookShop.manageSearchBooksAction">
<interceptor-ref name="myStack" />
<result name="success">/manageBooks.jsp</result>
</action>

</package>


</struts>



Mohana Rao wrote:Then do one thing make the namespace as / instead of "/JSP".

Surely, you are facing problem with namespace.

http://struts.apache.org/2.0.14/docs/namespace-configuration.html

Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

http://localhost:8084/BookShop/index.action(where is index action in struts.xml file)

Make this change http://localhost:8084/BookShop/index.jsp and in index.jsp redirect to login.action.
Raj Kuppala
Greenhorn

Joined: Nov 20, 2011
Posts: 4

Yes, you have to modify that as:

<welcome-file>index.jsp</welcome-file>

in your "web.xml" file.


Regards,
RP Royal.K,
Cognizant (India),
Mail Me: raj.prasad1224@gmail.com
Nagaraj Shivaklara
Ranch Hand

Joined: Dec 16, 2008
Posts: 75
I already have this,

Please find the below web.xml and index.jsp files:

web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


index.jsp:

<%--
Document : index
Created on : 13 Nov, 2011, 1:18:37 PM
Author : Nagaraj S K
--%>

<%@page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<!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>JSP Page</title>
</head>
<body>
<% response.sendRedirect("index.action"); %>
</body>
</html>


Still same problem..


Mohana Rao wrote:http://localhost:8084/BookShop/index.action(where is index action in struts.xml file)

Make this change http://localhost:8084/BookShop/index.jsp and in index.jsp redirect to login.action.
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

<% response.sendRedirect("login.action"); %> //Try to understand what the change i made.
Nagaraj Shivaklara
Ranch Hand

Joined: Dec 16, 2008
Posts: 75
Hi Mohana,

Thank you so much for your help, thanks for guiding me with patience. Finally issue is resolved.



Mohana Rao wrote:<% response.sendRedirect("login.action"); %> //Try to understand what the change i made.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jsp is not displaying in Struts2
 
Similar Threads
Struts2: Problem with form validation using validation xml
validation problem for cost : struts2
Problem With I18n feature of Struts2
problem calling static method using OGNL
How to valdate password and confirm password using validation framework in struts2?