0

I want to create a struts app which displays index.jsp file which contains link to the search.jsp file.Directory structure of Struts 1.2 app is as below

Struts 1.2 Directory Listing

enter image description here

The content of web.xml is as below

      <display-name>MiniHR</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>  
  <jsp-config>
   <taglib>
    <taglib-uri>http://struts.apache.org/tags-html</taglib-uri>
    <taglib-location>/WEB-INF/lib/struts-html.tld</taglib-location>    
  </taglib>
   </jsp-config>
   <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.</url-pattern>
    </servlet-mapping>
   <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>
</web-app>

The contents of struts-config.xml is as below

<global-forwards>
    <forward name="search" path="/search.jsp"></forward>
</global-forwards>

The content of index.jsp is as below

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<body>
    Add Employee<html:link forward="search">Search Employees</html:link>
</body>

Now when i run this app on eclipse its displaying HTTP Status 500 - as below

enter image description here

I tried few solutions but nothing seems to fix the problem.A Little Help would be appreciated.

I have added the war file in following URL

http://www.fileconvoy.com/dfl.php?id=g6daddfa41e8981249992832312c465146f9b6bc45

Thank you

6
  • web.xml file that you have mentioned, is it the full content of web.xml file? Commented May 9, 2013 at 4:48
  • yes that's the full content I tried to add struts-config in init-param but its not working any suggestions Commented May 9, 2013 at 4:50
  • Where is the struts action servlet mapping in your web.xml? Commented May 9, 2013 at 4:55
  • can you post the changes in web.xml so that i will try out I tried that let me edit my answer Commented May 9, 2013 at 4:56
  • The root cause of the problem as it says is : NullPointerException in TagUtils.computeURLWithCharEncoding exception What i see the problem may be with struts-tld version. Commented May 9, 2013 at 5:00

2 Answers 2

1

Struts assumes that all requests go through the Struts ActionServlet, which you aparently have not configured. Set up the Struts servlet with servlet-mapping *.do:

<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

Then you need to define some action mappings in your struts.xml that redirects to your view. You can't access the JSPs directly if you're using struts tags in your JSP.

Edit

You have updated your question with new web.xml content, so the above is covered. However, you still can't access the JSPs directly. You need to add an action mapping that forwards to your view.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for Reply Nilsh I tried that too but it aint worked for me
In that case, show the complete contents of struts.xml and the URL you're trying to access.
I have uploaded the war file in below URL fileconvoy.com/…
I will give a up vote thanks for the help u thought to offer Thank u so much
But how are you accessing the page? What is the URL you type into your browser? My point is that you can't access it with http://host:port/index.jsp, since you wouldn't go through the struts action servlet then, and you would get all sorts of exceptions.
|
1

You have html:link tag attribute forward wrong.

According to the Struts link tag specification:

forward - Use the value of this attribute as the name of a global ActionForward to be looked up, and use the module-relative or context-relative URI found there. If the forward is module-relative then it must point to an action and NOT to a page.

So, your global forward should point to a Struts Action and not a page.

I hope this resolves your problem.

See a related example here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.