Pages

Showing posts with label Struts. Show all posts
Showing posts with label Struts. Show all posts

Put Taglib in WEB.XML


Put your struts taglib files in Web-Inf and specify the below code in Web.Xml

Below XML attributes are load the taglib in jsp and parse the HTML elements.


Remove jsessionid in URL - Struts


URL Rewriting is used to remove the URL jsesssionid in java based web application.By default, Web app URL are look like this :
http://www.bhuvanlabs.com/login.do;jsessionid=539F373633D345

Above URL fails in Security concerns because session is maintain in URL. User can miss use the data by session Id.It's possible that some web sites may use cookies to track user browsing patterns.
Sessions can be implemented with two underlying mechanism
-->cookies
-->URL rewriting

To remove the jsessionid , want to tell in web.xml
<session-config>
    <tracking-mode>COOKIE</tracking-mode>
</session-config>
Now URL look like this..
http://www.bhuvaneslabs.com/login.do

Customized 404 Error Page in Struts

By Default, Struts will show a default 404 error page. If you want custom error page, you want to declare xml attributes in web.xml. Mention the error code and JSP page in xml attribute when the particular error happen it redirects to the custom page in your directory not to the default page.
Put your error404.jsp in WebContent directory in your application.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <display-name>Custom Error Page</display-name>

  <!-- Standard Action Servlet Configuration -->
  <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>2</load-on-startup>
 </servlet>

  <!-- Standard Action Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

  <!-- The Usual Welcome File List -->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <!-- The Custom Error Page List -->
  <error-page>
    <error-code>404</error-code>
    <location>error404.jsp</location>
  </error-page>

</web-app>