facebook

starting with struts

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #313431 Reply

    menyarito
    Member

    Hi,
    I start with struts in myeclipse, I started doing a program that prompts for the
    color of a fruit after it displays the name of the fruit, my problem is that if you click on send it returns a blank page…here are my files
    index.jsp

    <%@ page language="java" pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> 
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
     
    <html> 
        <head>
            <title>JSP for IndexForm form</title>
        </head>
        <body>
            <html:form action="/index">
                couleur : <html:text property="couleur"/><html:errors property="couleur"/><br/>
                <html:submit/><html:cancel/>
            </html:form>
        </body>
    </html>
    
    

    fruit.jsp

    <%@ page language="java" pageEncoding="ISO-8859-1"%>
    
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html locale="true">
      <head>
        <html:base />
        
        <title>fruit.jsp</title>
    
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    
      </head>
      
      <body>
      <bean:write name="couleur" scope="request"/>
    <a href="index.jsp">Retour</a>
      </body>
    </html:html>
    

    IndexAction.java

    /*
     * Generated by MyEclipse Struts
     * Template path: templates/java/JavaClass.vtl
     */
    package com.yourcompany.struts.action;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import com.yourcompany.struts.form.IndexForm;
    
    /** 
     * MyEclipse Struts
     * Creation date: 12-23-2010
     * 
     * XDoclet definition:
     * @struts.action path="/index" name="indexForm" input="/index.jsp" scope="request" validate="true"
     * @struts.action-forward name="fruits" path="/fruit.jsp"
     */
    public class IndexAction extends Action {
        protected String calculeFruit (String couleur) {
            if(couleur.equals("rouge")) {return ("Fraise");}
            else if(couleur.equals("jaune")) {return ("Banane");}
            else if(couleur.equals("vert")) {return ("Pome");}
        return(null);}
        public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response) 
            
            throws IOException, ServletException {
                String cible="succes";
                String couleur, fruit=null;
                if (form!=null){
                    IndexForm formulaire = (IndexForm)form;
                    couleur = formulaire.getCouleur();
                    fruit=calculeFruit(couleur);
                    formulaire.setFruit(fruit);}
                if (fruit==null) {cible="echec";}
                return (mapping.findForward(fruit));}
                }
        
    

    thank you in advance for your help

    #313439

    support-swapna
    Participant

    menyarito,

    You need to specify the Action Forwards in the Forwards tab at the time of creation of the Action.

    From the code it looks like you are trying to forward to a jsp with the name of a fruit. So make sure you have the jsp and it is at the correct path.

    Here is the tutorial for working with struts in MyEclipse. Please have a look.
    http://www.myeclipseide.com/documentation/quickstarts/struts/

    Hope this helps.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: starting with struts

You must be logged in to post in the forum log in