How to do Pagination in struts application????

My struts application lists the records from database using iterator.
I use ArrayList in Action class and i access the list in JSP through by setting request variable in action class.But if i have 10 fields which are multi line format such as address.I need to restrict records 4 per page.how to do that??
I am stuck in pagination of struts.

Use dispatch action.Here i am displaying only 2 records per page because my appln required 10 fields you can extend it to any count.You can use this..
public class FeedListAction extends DispatchAction {
     public ActionForward list(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response)
             throws IOException {
          //List method is called first when we want to list our records.
                                  FeedForm frm = (FeedForm)form;
                                  ArrayList feedlist = new ArrayList();
          //session is used to know where are we..
                                  HttpSession ses = request.getSession(true);
          // two parameters which will be used to limit the records for perticular page.
                                  String s = "0";
                                  String e ="2";
          //call the method which will be used to display the records..
                                  feedlist = frm.getEmployees(Integer.parseInt(s),Integer.parseInt(e));
          //set the list so that jsp page will use to display it.
                                  request.setAttribute("list", feedlist);
          // set the attributes so that they are used while navigation and
          // these attributes wiil be used by the  other methods of Dispatch action.
                                  ses.setAttribute("s", s);
                                  ses.setAttribute("e", e);
          //Find the success page.
                                  return mapping.findForward(success);
          //end of List method
     public ActionForward next(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response)
              throws IOException {
                                  //here add code for session.          
                                int en =0;
                                int st=0;
                                st = Integer.valueOf( s ).intValue();
                                  en = Integer.valueOf( e ).intValue();
// to know whether next has exceeded the recordset limit we need to take number of rows
// which can accessed through nrows function.
                                  int nrows = frm.rows();
                                  if(st==(nrows-2)){
                                       st = nrows-2;
                                  }else{
                       st=st+2;en=2;                                      
  //go for setting values in your module (which will interact with dadtabase to fetch records).                                           ses.setAttribute("s",Integer.toString(st));
//then set session attribute.                                  
                                  return mapping.findForward(success);
       //end of next method.     
     }

Similar Messages

  • How to add i18n features to a Struts application?

    How to add i18n features to a Struts application?
    txs!

    How to add I18N to Struts application
    operation:
    1) provide your native ascii encoded properties file.
    2) set the correct language priority. (As to IE: Tools - Internet Options - Languages
    3) coding: add correct encoding in your web page, exp. for zh_CN:
    <%@ page contentType="text/html; charset=gb2312" %>
    utility batch file:
    native2ascii -encoding gb2312 MessageResources_zh_CN.txt MessageResources_zh_CN.properties
    copy MessageResources.txt MessageResources_en_US.properties
    note
    Before you run the utility batch file, you should first add %JAVA_HOME%/bin to system %PATH% environment variable.

  • How to test Struts application

    hai
    I have created my application in Struts at the same time I have to do testing also, I am new to Testing. Can ayone help me how to do testing for struts application, please...........
    Thanks in advance..........

    hai
    I have created Login page so, I want to test my LoginAction...
    Can anyone tell me which tool can I use and how to write testcase for my application..
    Thanks in advance..........

  • How to call a struts application in a portlet

    How to call a struts application in a portlet. I have two different ear's. In one ear I have my struts application and in one war i have a struts portlet. In the struts portlet provider.xml defaultAction tag can i call the action class .do which in other ear (ie my struts application ear).Can anyone suggest me whether this is the right way or else can u suggest me with some other thing.
    Waiting for ur responses.
    Thanks and Regards,
    Dhanu.

    Hi Dhanu,
    Your Struts Portlet will not be avialble via a URL as it is completely dependent on Oracle Portal Environment. The Provider for the Portlet is alone available via a URL - you would have registered your Portlet using the URL of the Provider.
    Your Struts application, which does not rely on the Oracle Portal Environment, is defeitely accessible from a URL. It's just another web application that uses the popular Struts Framework.
    Hence, you can use the URL ( the starting point - a JSP, Servlet, etc. ) of your Struts Application to "call" the application in your Struts Portlet. I don't think you need to fiddle with the parameters in Provider.xml.
    Moreover, <defaultAction> in Provider.xml should have the URL of a Struts Action Class - the mapping in the
    struts-config.xml should map the .do action to the right JSP file.
    You can have a look at Metalink Note : 331069.1 for a good insight into the <defaultAction> Tag.
    Regards,
    Sandeep

  • How to install struts application in a real web server

    I have a problem about installing my struts application into web server..
    I can run my application under eclipse websphere development studio 5.0 web server but I don't know How I install it a real webserver (Apche,Unix,Tomcat or etc.) under location something like " http://cmpe.emu.edu.tr/ " .
    I have small exprerinece about web servers.. So if you can state your answers clearly, I'll be really grateful...
    Ergin DEMIREL
    Thanks in Advance..

    Web servers like Apache or M$ IIS serve up static HTLM content. They don't handle Java servlets/JSPs by default. You need a servlet/JSP engine for that. Tomcat is one. All J2EE-compliant app servers have one, too (e.g., WebSphere, WebLogic, JBoss, etc.)
    If you're asking how to do it with Apache the answer is: bolt Tomcat on top of Apache. There are docs on the Tomcat site to tell you how to do that.
    %

  • How to deploy a struts application on weblogic

    I tried to deploy the struts application on weblogic. It is not able to recognize the taglib files for jsp. I have included the .tld files.

    Hi,
    I have installed WebLogic 8.1.
    And Created a Basic WebLogic Server Domain.
    Started the server. Server is running.
    When I try http://localhost:7001.
    It is giving error as follows...
    Error 404--Not Found
    From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
    10.4.5 404 Not Found
    The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.
    If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.
    Can anybody assist me pls.
    Regards
    Siva

  • Error while deploying struts application in tomcat

    Hi,
    I'm getting the following error when I start Tomcat using while auto-deploying a struts application.
    2005-09-21 15:28:17 - ContextManager: Adding DEFAULT:/cna
    2005-09-21 15:28:18 - Ctx(/cna) : Validating web.xml
    2005-09-21 15:28:18 - Ctx(/cna) : Class not found: org.apache.struts.action.Acti
    onServlet
    2005-09-21 15:28:18 - Ctx(/cna) : Class not found: org.apache.axis.transport.htt
    p.AdminServlet
    In case anyone is aware how to resolve this issue, please help.
    Thanks,
    Roseline

    Hi,
    1] Remove following from server.xml
    <Context path="/SEA" docBase="SEA" debug="0"/>
    2] Paste SEA.WAR (test WAR file) into /webapps of TOMCAT
    3] Start Tomcat Server - This will create SEA folder under webapps
    4] Stop server.
    5] Add following to server.xml
    <Context path="/SEA" docBase="SEA" debug="0"/>
    6] Start Tomcat Server
    7] Access the URL.
    This will work. Somehow Tomcat does not extract war file contents which are mentioned in server.xml.
    I have Apache Tomcat 4.0.3 and faced this problem. The above solution works for it.
    Regards,
    Sandesh
    hi.
    I have put my SEA.WAR (test WAR file) into /webapps of
    TOMCAT.
    I checked the server.xml and put:
         <Context path="/SEA" docBase="SEA" debug="0"/>
    I restarted TOMCAT and tried to execute the file:
         http://localhost:8080/SEA/index.jsp
    But I got error message:
    Apache Tomcat/4.0.3 - HTTP Status 404 -
    /SEA/index.jsp
    What was happenning?
    Anyone can help me?
    Thank you.

  • "Navigator" via JSF in a Struts Application (struts-faces)

    Hi!
    I got an existing Struts application which uses some includes to display a "Menu" on the left side with several links to navigate through the Webapp. Each of the Links points to a Struts-Action, that does some business logic and redirects any of a bundle of JSPs... Each of the JSPs is including this "navigation-jsp".
    Now i want to realize this Navigation with JSF and a TreeViewer (similar to the one in demo components) but the problem i face atm is, that when i click a link, and come back to any of the JSPs (after struts-action) how should this Tree-Navigator be rendered correctly???
    As said in topic, im using struts-faces.
    Any ideas?
    Greetings
    Patrick

    please guys - try to help me :-(

  • Migrating struts application from 10.1.2 to 10.1.3.1

    I've tried migrating my struts application from using JDev 10.1.2 to 10.1.3.1. When I try to open up the struts-config.xml file, I get a Java runtime exception error. I am using JDK 5.0.60.5. I'm not sure how to fix this....
    Message
    BME-99004: A Java runtime exception has occurred.
    Cause
    This exception should have been dealt with programmatically. The current activity may fail and the system may have been left in an unstable state. The following is a stack trace.
    java.lang.ClassCastException: oracle.adfdt.controller.struts.diagram.db.shape.StrutsDataActionNode
         at oracle.adfdt.controller.struts.diagram.shape.StrutsPageLink.connect(StrutsPageLink.java:79)
         at oracle.bm.diagrammer.shape.BaseDiagramEdge.validate(BaseDiagramEdge.java:3176)
         at oracle.bm.diagrammer.registry.RBaseShape.validate(RBaseShape.java:788)
         at oracle.bm.diagrammer.BaseDiagram.validateOnLoad(BaseDiagram.java:6436)
         at oracle.bm.persist.diagram.impl.BaseDiagramReader.loadDiagram(BaseDiagramReader.java:141)
         at oracle.bm.diagrammer.BaseDiagram.loadDiagram(BaseDiagram.java:1381)
         at oracle.adfdt.controller.diagram.PageFlowDiagram.loadDiagram(PageFlowDiagram.java:108)
         at oracle.bm.addinUtil.IDEAppContext.buildDiagram(IDEAppContext.java:2269)
         at oracle.bm.addinUtil.DiagAppPanel.buildDiagram(DiagAppPanel.java:50)
         at oracle.bm.addinUtil.IDEAppContext.openLoad(IDEAppContext.java:3735)
         at oracle.bm.addinUtil.IDEAppContext.open(IDEAppContext.java:3368)
         at oracle.adfdt.controller.diagram.PageFlowEditor.open(PageFlowEditor.java:82)
         at oracle.ideimpl.editor.EditorState.openEditor(EditorState.java:239)
         at oracle.ideimpl.editor.EditorState.createEditor(EditorState.java:147)
         at oracle.ideimpl.editor.EditorState.getOrCreateEditor(EditorState.java:90)
         at oracle.ideimpl.editor.SplitPaneState.canSetEditorStatePos(SplitPaneState.java:231)
         at oracle.ideimpl.editor.SplitPaneState.setCurrentEditorStatePos(SplitPaneState.java:194)
         at oracle.ideimpl.editor.TabGroupState.createSplitPaneState(TabGroupState.java:103)
         at oracle.ideimpl.editor.TabGroup.addTabGroupState(TabGroup.java:275)
         at oracle.ideimpl.editor.EditorManagerImpl.createEditor(EditorManagerImpl.java:1261)
         at oracle.ideimpl.editor.EditorManagerImpl.createEditor(EditorManagerImpl.java:1196)
         at oracle.ideimpl.editor.EditorManagerImpl.openEditor(EditorManagerImpl.java:1131)
         at oracle.ideimpl.editor.EditorManagerImpl.whenOpenEditor(EditorManagerImpl.java:2332)
         at oracle.ideimpl.editor.EditorManagerImpl.handleDefaultAction(EditorManagerImpl.java:1893)
         at oracle.ide.controller.ContextMenu.fireDefaultAction(ContextMenu.java:343)
         at oracle.ideimpl.explorer.BaseTreeExplorer.fireDefaultAction(BaseTreeExplorer.java:1576)
         at oracle.ideimpl.explorer.BaseTreeExplorer.dblClicked(BaseTreeExplorer.java:1913)
         at oracle.ideimpl.explorer.BaseTreeExplorer.mouseReleased(BaseTreeExplorer.java:1934)
         at oracle.ideimpl.explorer.CustomTree.processMouseEvent(CustomTree.java:176)
         at java.awt.Component.processEvent(Component.java:5253)
         at java.awt.Container.processEvent(Container.java:1966)
         at java.awt.Component.dispatchEventImpl(Component.java:3955)
         at java.awt.Container.dispatchEventImpl(Container.java:2024)
         at java.awt.Component.dispatchEvent(Component.java:3803)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
         at java.awt.Container.dispatchEventImpl(Container.java:2010)
         at java.awt.Window.dispatchEventImpl(Window.java:1774)
         at java.awt.Component.dispatchEvent(Component.java:3803)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    Action
    If further errors occur, you should restart the application.
    Also, report the problem on the JDeveloper forum on otn.oracle.com, or contact Oracle support, giving the information from this message.
    ________________________________________________________________________________

    Yes, but the application under 10.1.3 points to the application.jws file in the old 10.1.2 directory.
    I want the application to point to the .jws file JDeveloperApplication/<application>/<application>.jws.
    10.1.3 keeps this pointer somewhere and would like to change it. I scanned the jdev directory for files containing <application>.jws, and found it in the binary file jdev/system/oracle.jdeveloper.10.1.3.36.73/system.sys file, and the ide.properties file, and the system/oracle.ide.10.1.3.26.73/windowinglayout.xml file.
    None of these files seem to be the place to make the adjustments.
    I guess the more general question for me is "How should JDeveloper be configured to allow for migration of applications? (It does not seem to be a no-brainer!) How should it be configured when additional libraries have been included in the list libraries of prior JDeveloper version and need to be migrated/duplicated to a new version of JDeveloper? How are connections supposed to be migrated (for database, cvs, application servers)? How should JDeveloper be configured for team use? (Each member of a team should maintain identical JDeveloper configurations. Yes?)"
    But, first things, first. How do I point a JDeveloper application to a different .jws and application directory?

  • How can I stop the Struts messages

    How can I stop getting Struts messages such as:
    RequestProcessor - -Processing a 'POST' for path '/login'RequestProcessor - -Processing a 'GET' for path '/Welcome'
    I cannot deploy my application on the production server because these messages will be all sent to the log files through System.out.
    In one of other postings, someone suggested adding the commons-logging.properties, and the simplelog.properties files to the project. Unfortunately, that didn't help.
    I appreciate your help.

    Struts 1.1 Beta-2 (which JDev 9.0.3, 9.0.3.1, and 9.0.3.2 ship with) has a bug where you cannot silence all of the diagnostics.
    It's been fixed in the Struts 1.1 final release.
    See this article on my web log for how to upgrade the BC4J Toy Store appliacation to use Struts 1.1 Final. You can use the tips to then upgrade your own application, too.
    http://radio.weblogs.com/0118231/2003/07/07.html

  • Need help implementing AJAX in an existing Struts Application

    Hi!
    I am trying to implement AJAX in my existing Struts Application. I need a good approach to go ahead and implement Ajax. I was thinking.. may be i will have to club all the code in the forms n actions (in the current Struts application) to one form and action, So I can easily include the dynamic content in the page.
    Please let me know if you have any ideas of how to implement AJAX in a fully developed Struts application.
    Thanks,
    Swapna.

    Hello Friends,
    Check out whether the link below could be of somehelp for you folks...
    http://www.it-eye.nl/weblog/2005/12/13/ajax-in-struts-implementing-dependend-select-boxes/
    http://today.java.net/pub/a/today/2005/10/27/sprinkle-ajax-magic-into-struts-webapp.html
    http://www.theserverside.com/news/thread.tss?thread_id=37355
    http://getahead.ltd.uk/dwr/examples/lists
    http://www.componentsource.com/products/backbase-ajax-struts/summary.html
    http://www.jibbering.com/2002/4/httprequest.html
    added to it there are few implementation frameworks which are addressing this issue you may further search on it and update abt the info which could be very much useful for all of the ppl out here.
    and there is a current thread running on the same topic it'd really appriciated if u can accomadate ur posts there.
    http://forum.java.sun.com/thread.jspa?threadID=784924&tstart=0
    REGARDS,
    RAHUL

  • How to Enable Log4j in Struts

    Hi,
    I have a struts application and I need to implement a logger for it. I would like to use Log4j but am having problems initializing it.
    Because I am using struts, I do no have access to the Action servlet and so cannot place the intiializing code in the servlets init() method.
    Is there a way of using the struts-confix.xml file to enable Log4j logging ?
    Basically I need the application to load up the log4j.properties file using
    PropertyConfiguratior.configure("log4j.properties");
    But how do I do this in Struts ??
    thanks
    Paul

    Struts core library uses commons logging , some drop log4j.properties files /WEB-INFO/classes, cooomons lgging will pick up and initialize.
    Other way is write a plug-in and load the log4j configuration
    ==============================================
    1. Add plug in to struts-config files like validator plug in
    <plug-in className="com.tests.utl.Log4jPlugin">
    <set-property
    property="log4jconfig"
    value="/WEB-INF/log4j.xml"/>
    </plug-in>
    2. Drop log4j.xml file in "/WEB-INFO" folder
    3. Sample "log4j" plug in java class, here key is define property "log4jconfig" as plugin setter/getter, struts will set the value read from struts-config.
    ================================
    public class Log4jPlugin implements PlugIn {
    private String log4jconfig;
    public Log4jPlugin() {
    public void destroy() {
    System.out.println("Destroying Hello World PlugIn");
    public void init(ActionServlet servlet, ModuleConfig config)
    throws ServletException {
    URL url =null;
    try {
    url = servlet.getServletContext().getResource(log4jconffile);
    System.out.println(" url " + url);
    } catch (MalformedURLException ex) {
    ex.printStackTrace();
    DOMConfigurator.configure(url);
    public String getLog4jconfig() {
    return log4jconfig;
    public void setLog4jconfig(String log4jconfig) {
    this.log4jconfig = log4jconfig;
    }

  • Sample struts application

    Hello,
    I am new to struts, i installed struts in my tomcat web server 5.0, and allso i installed the struts examples in my tomcat server,
    i studied all the examples in the strutsexamples.war but it wont help me,i need to develope a small application using struts with the back end of mysql server5.0, i dont know how to retrive data from database and show it in page using struts,
    i know very well in jsp, but i dont know struts,
    plese any body give some useful reference links for developing struts application.
    thanking u in advance.
    plese help me.

    There are numerous resources around online, but I found this particular one very useful. It gives a good overview of several things in Struts and then you can build on.
    http://courses.coreservlets.com/Course-Materials/struts.html

  • Sorting Columns in a Struts application

    Hi,
    I am new to struts and I would request help on the following.
    I have a struts application that uses struts nested tags to display data from a database table on a JSP page in a tabular manner in multiple columns. I want to be able to sort (either asending or decending) the results by clicking on a column header . Could someone provide a code example as how this could be done?
    Thanks.

    provide the links on your jsp page like
    sort asc
    sort desc
    and in your action file
    sort the query accrding to result variable
    if("asc".equals(result)){
    query for ascending
    if("desc".equals(result)){
    query for desc
    }

  • Error when running the struts application

    Hi
    i am getting this error when i run my struts application. Do i need to install the xerces parcer and should my local have the ANT. If so how should i confingure ANT
    /JSP/Login.jsp(12,0) Attribute name invalid for tag form according to TLD
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
         org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
         org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:236)
         org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1200)
         org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:821)
         org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1512)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
         org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2399)
         org.apache.jasper.compiler.Node$Root.accept(Node.java:489)

    Ya I guess everything is right in both the files. Let me paste the contents :-
    WEB.XML
    <!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>
    <display-name>My Inventory</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>Login.jsp</welcome-file>
    </welcome-file-list>
    <taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.TLD</taglib-location>
    </taglib>
    </web-app>
    STRUTS-CONFIG.xml
    <!DOCTYPE struts-config PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
    "http://struts.apache.org/dtds/struts-config_1_3.dtd">
    <!--
    Default configuration file for examples application.
    Each module also has its own struts-config under: /WEB-INF/$MODULE/
    @version $Revision: 1.9 $ $Date: 2006-12-03 11:32:52 -0600 (Sun, 03 Dec 2006) $
    -->
    <struts-config>
    <form-beans>
    <form-bean name="Loginform" type = "com.myInventory.Loginform"></form-bean>
    </form-beans>
    <global-exceptions/>
    <global-forwards
    <!-- utilize a custom ActionForward as an example only -->
    </global-forwards>
    <action path="/Login" type="com.myInventory.actions.Loginaction" name="Loginform" input="/Login.jsp">
              <forward name="login_target_success" path="/success.jsp"/>
              <forward name="login_target_failure" path="/login.jsp"/>
              </action>
    </action-mappings>
    <message-resources parameter="MessageResources"/>
    </struts-config>

Maybe you are looking for