- This topic has 4 replies, 2 voices, and was last updated 20 years, 9 months ago by Riyad Kalla.
-
AuthorPosts
-
Prasanna TuladharMemberHi !
I am using the latest version of MyEclipse 2.7R2. I have installed it correctly and created a web module with struts capabilities. I am unable
to use the global forward feature to work which works if I give a full path.This works fine (all the jsp, Action/ActionForm works well)
http://localhost:8080/DataQualitNew/jsp/start.jspThis does NOT eventthough I have enabled the GLOBAL FORWARD
as shown below to avoid index.jsp page from showing up
http://localhost:8080/DataQualitNew/i.e, The request is not redirected to start.jsp page as expected.
Is this some configuration problem or a bug ?
Here is my struts config which did not work.
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<!DOCTYPE struts-config PUBLIC “-//Apache Software Foundation//DTD Struts Configuration 1.1//EN”
“http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd”>
<struts-config>
<data-sources/>
<form-beans>
<form-bean name=”MakeGuessForm” type=”sample.MakeGuessForm”/>
</form-beans>
<global-exceptions/>
<global-forwards>
<forward name=”start” path=”/jsp/start.jsp”/>
<forward
name=”main”
path=”/jsp/start.jsp”/>
</global-forwards>
<action-mappings>
<action name=”MakeGuessForm” path=”/makeGuess” scope=”session” type=”sample.MakeGuessAction”>
<forward name=”match” path=”/jsp/match.jsp”/>
<forward name=”nomatch” path=”/jsp/nomatch.jsp”/>
</action>
</action-mappings>
<controller/>
</struts-config>
Riyad KallaMemberplease post your web.xml, struts will only apply matches to things that get sent to the action servlet. Most likely you have a default mapping to map all URLs ending in “.do” to the action servlet, which THEN looks in the struts-config file. So when you are typing the root URL of your app (http://localhost:8080/DataQualitNew/ ) there is no .do to match, so the request is handled purely by the web.xml mappings which there is none for so it returns nothing.
In your struts-config you have an action with a path set, this path in a browsers URL most likely looks like:
http://localhost:8080/DataQualitNew/makeGuess.doand then in your struts-config you are telling the action servlet “hey send this guy back either the match.jsp or nomatch.jsp page contents as a reply”. What most people do is setup a forward of say “/home” which means “home.do” in the browsers URL. And then in your index.jsp or start.jsp you enter an immediate redirect to that home target which is then handled by struts.
What you could also do is to setup a URL Mapping in the web.xml file that maps certain URLs over to struts .do entries.
I hope this helped.
Prasanna TuladharMember<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<!DOCTYPE web-app PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”
“http://java.sun.com/dtd/web-app_2_3.dtd”>
<web-app>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping><taglib>
<taglib-uri>/WEB-INF/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
</web-app>
Prasanna TuladharMemberHi !
I have written a servlet that will forward any request at root to the designated jsp.
This works now. I think even configuring welcome-file in web.xml should work. I am not experirenced in struts, so my apologies for taking your time.
While writing JSP I got some “Nullpointer Exception” from the JSP parser. I will send the details if I catch it again. Once again thanks a lot. Such propmt reply are an inspiration to use your tool.
Riyad KallaMemberNo problem, I’m glad you found a solution for the time being. Yes, keep us posted on that NPE if you see it again.
-
AuthorPosts