Eclipse example with request data issues default output folder

Eclipse I am building one struts with request data example.

I went to file---dynamic web project---then gave name StrutsReqWithDataNoForm2--- source folders on build path src(Can I change this folder???)
---default outputlocation instead of 'build/classes' I gave as 'classes'(my intention is to see classes directory under WEB-INF/classes.

But after creating project under WEB-INF i do not see 'classes' folder(is it is invisible do i need make some changes to make it visible). I need to create 'actions' folder under 'classes' and eventually write a 'MaintenanceAction.java action class' there.
I wonder why I cannot see default output folder any where to do this. How can i see it and add following class to it to redirect to corresponding jsp based on the request parameter selection and action mapping.

/StrutsReqWithDataNoForm2/WEB-INF/classes/actions/MaintenanceAction.java
MaintenanceAction.java
package actions;
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;
public class MaintenanceAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String nextPage = "";
try {
// No From bean. So read the data from request.
String page = request.getParameter("page");
// If page is "sales", then it goes to the page whose forward is named
//with "sales"
nextPage = page;
} catch (Exception e) {
}
// Finish with
return mapping.findForward(nextPage);
}
}

I already created 2 jsps called Sales.jsp and Inventory.jsp






package actions;
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;
public class MaintenanceAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String nextPage = "";
try {
// No From bean. So read the data from request.
String page = request.getParameter("page");
// If page is "sales", then it goes to the page whose forward is named
//with "sales"
nextPage = page;
} catch (Exception e) {
}
// Finish with
return mapping.findForward(nextPage);
}
}



Sales.jsp
<HTML>

<h1>Welcome to Sales Page</h1>
</HTML>



Inventory.jsp
<HTML>
<h1>Welcome to Inventory Page</h1>
</HTML>

DefaultOutputFolder.docx
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gudii9Author Commented:
It worked fine as in the attachment. Following are the URLs I have used.

http://localhost:8080/StrutsReqWithDataNoForm2/maintenance.do?page=sales

http://localhost:8080/StrutsReqWithDataNoForm2/maintenance.do?page=inventory

http://localhost:8080/StrutsReqWithDataNoForm2/welcome.do

Struts-config file looks like

<?xml version="1.0" encoding="UTF-8"?>
<!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 -->
      <data-sources></data-sources>
      <!-- Form Beans -->
      <form-beans></form-beans>
      <!-- Global Exceptions -->
      <global-exceptions></global-exceptions>
      <!-- Global Forwards -->
      <global-forwards></global-forwards>
      <!-- Action Mappings -->
      <action-mappings>
            <action path="/welcome" forward="/jsps/struts/Welcome.jsp" />
<action path="/maintenance" type="actions.MaintenanceAction">
<forward name="sales" path="/jsps/struts/Sales.jsp" />
<forward name="inventory" path="/jsps/struts/Inventory.jsp" />
</action>
      </action-mappings>
      <!-- Message Resources -->
</struts-config>



web.xml looks like

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">
  <display-name>Struts Test from coreservlets.com</display-name>
 
  <!-- Standard Action Servlet Configuration (with debugging) -->
  <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>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>2</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>

</web-app>

My question still remains why the build/classes folder is not visible. Even though I changed to classes then also it is invisible. Please advise
InventoryPAge.JPG
0
gudii9Author Commented:
I changed the Action class as below

instead of
//String page = request.getParameter("page");

I added below line
String page =      (String) request.getSession().getAttribute("page");      

It is not leading to corresponding Sales or Inventory page any more. It just dispays blank page. Please advise


package actions;
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;
public class MaintenanceAction extends Action {
      public ActionForward execute(ActionMapping mapping, ActionForm form,
                  HttpServletRequest request, HttpServletResponse response)
      throws Exception {
            String nextPage = "";
            try {
                  // No From bean. So read the data from request.
                  //String page = request.getParameter("page");
                  String page =      (String) request.getSession().getAttribute("page");
                  // If page is "sales", then it goes to the page whose forward is named
                  //with "sales"
                  nextPage = page;
            } catch (Exception e) {
            }
            // Finish with
            return mapping.findForward(nextPage);
      }
}

When I go to

http://localhost:8080/StrutsReqWithDataNoForm2/maintenance.do?page=inventory

Says cannot go to Null forward. Please advise
NullForward.JPG
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

mccarlIT Business Systems Analyst / Software DeveloperCommented:
Firstly, just a bit of house keeping; if you have a separate, non-related question you should open a new question, that way you will get more people looking at it. Just adding it as a comment to a different question will generally mean that nobody will see it.

As to the original question, the output directory is for compiled classes, you don't put you .java files there because there are only source files, and nothin will happen with them. You would put your MaintenanceAction.java in the src/actions folder. That way, Eclipse knows about it and will compile the class for you, which will be compiled into the output directory that you have specified. You don't even need to worry about where that is because Eclipse will make sure your classes are on the classpath for Tomcat when it starts up. That's the beauty about IDE's, they do that housekeeping stuff for you!

And as for the second question, it was working originally because you were retrieving the 'page' parameter from the request correctly. Then you changed to try and retrieve an attribute called 'page' from the session, and so it doesn't work because there is no 'page' attribute in the session (hence the error saying it can't find 'null'). Session attributes and request parameters are two totally different things. There won't ever be any 'page' attribute in the session until you put one there (in either the current request or a previous request).   Maybe you need to explain why you wanted to try and make that change in the first place? But what the code is doing seems absolutely correct and normal for the change that you made.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
>>>You don't even need to worry about where that is because Eclipse will make sure your classes are on the classpath for Tomcat when it starts up.


If I wish to change to default output directory do I have option?

Or I just have to accept default output directory as build/classes all the time when using eclipse. Please advise
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You can (and probably successfully did) change the output directory. It's just what you were trying to change it too, and the reasons that you were trying to change it were wrong!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.