Link to home
Start Free TrialLog in
Avatar of heman7719
heman7719

asked on

Learn Struts.. prt 2

Hi, after go through the URL and aritcel regarding sturts, I have some doubts and question. beofre that, do share me your attention on listening to my explanation on Sturts.

1st version (Dummy version)
====================

1. each time user (browser) will call the controller (Action Servlet).
2. Then in the ActionServlet,  it will determine or delegates the responsibilities to JSP/Classes/Form based on the sequence.
3. The sequencing is set in the web.xml program.
4. The classes is my own customize java program on achieve something or control or validate something.
5. Display the end-result to user using JSP with JSTL tag.
6. One cycle end. If user want to have another round, thwe whole cycle will repeat again.


2nd version (more technical)
====================

1.  Browser willc all the servlet. based on the web,xml program, it'll map the location of the ActionServlet in using XML tag.
2. After that ActionServlet will delegate the responsibilities using struts-config.xml to map some of the Action Class (Java class), JSP. In sturts-config.xml, it's also shown the sequence of the loading program (JSP/JavaClass).
3. In the Action Class, I can have my own custom method or custome code to perfom my own custom logic.
4. JSP view is using the JSTL concepts plus the session functionalities.


Question:

1. Do i need to code the struts-config.xml manually? Is it exist when I download the struts.jar into my project? This is because my web.xml will come out automatically.
2.   What is ActionForm? It's seems that it's esential for me to have this before my JSP page can come out.
3. ActionError. What is this? Is it prebuild by struts or I have code myself.
4. Where should i put the strut-confi,xml is I need to create myown. WEB-INF/lib , or WEB-INF/Classes?


i think overall, I understand this framework will ease my time on creating the program for me. But I don't know which one is inbuild and which one I have to create my own.

Please correct me for the explanation above if there is anything wrong.

ASKER CERTIFIED SOLUTION
Avatar of mr_cool
mr_cool

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
1. Do i need to code the struts-config.xml manually? Is it exist when I download the struts.jar into my project? This is because my web.xml will come out automatically.
You can use a tool like J-Builder wich comes with a GUI for editing thre struts-config.xml

2.   What is ActionForm? It's seems that it's esential for me to have this before my JSP page can come out.
The ActionForm is a Bean wich represents the FORM Data.

3. ActionError. What is this? Is it prebuild by struts or I have code myself.
see mr_cool

4. Where should i put the strut-confi,xml is I need to create myown. WEB-INF/lib , or WEB-INF/Classes?
see mr_cool
Avatar of heman7719
heman7719

ASKER

Thank you mr_cool. If my explanation is not 100% accurate. Maybe you can explan your own version of sturts for me. Sometime words from mouth is more easy to understand. :-)
But I don't see the "example "struts-blank.war" ".


Oliver_Dornauf, thanks for your time.  Maybe youcan put the sturs definition in a more easier understandable. By the way, why the "FORM" is so special. i think there is a meaning behind it right? is it thjis FORM is referring to the input page from the user?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mr_cool, kokchoon, yes i saw the .war file already... now is going throught the step-by-step lesson guide in the
http://www.reumann.net/do/struts/lesson1/step9

:-)

heman7719 ,

I said you did not cover 100% of the possible execution paths of struts.  For example, one possible path is.

1. Submit for data
2. Form data is processed by the action form
3. the Action processes the request but encounters an exception (SQLException, NullPointer, etc...)
4. Action throws the exception
5. The struts controller catches the exception and passes control to the global exception handler.

This is just one path, there are many.  You described the "happy" path and it was a reasonable description.
Dont feel bound by this happy path though, you can do ANYTHING you want.

eg. instead of

5. Display the end-result to user using JSP with JSTL tag.

how about:

5. Create an xml document with the results and use xsl to display the results to the user

Have fun with the tutorial :)
ha.. mr_cool, I think that path will only come into me after I familiar with the "happy" path first... ha... because until now I am still not happy yet.... :-)

Yes, the tutorial is a fantastic choice. TQ for your recommdation. This weekend I have a serious look into it. Furthermore it's come with the .war file as well.

Let me get back to you after the reading. For sure I have thousand of question.. ha...
guys.. the first war file i download can't be run... any idea from the exception below.


index.jsp [-1:-1] java.lang.ExceptionInInitializerError: java.lang.NullPointerException
        at org.apache.struts.util.MessageResources.getMessageResources(MessageResources.java:577)
        at org.apache.struts.taglib.html.BaseHandlerTag.<clinit>(BaseHandlerTag.java:108)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:115)
        at org.apache.strutsel.taglib.html.ELRewriteTagBeanInfo.class$(ELRewriteTagBeanInfo.java:88)
        at org.apache.strutsel.taglib.html.ELRewriteTagBeanInfo.getPropertyDescriptors(ELRewriteTagBeanInfo.java:88)
        at java.beans.Introspector.getTargetPropertyInfo(Introspector.java:341)
        at java.beans.Introspector.getBeanInfo(Introspector.java:291)
        at java.beans.Introspector.getBeanInfo(Introspector.java:76)
        at org.apache.jasper.compiler.TagCache.setTagHandlerClass(TagCache.java:116)
        at org.apache.jasper.compiler.TagBeginGenerator.init(TagBeginGenerator.java:146)
        at org.netbeans.modules.web.jspparser.AnalyzerParseEventListener.addGenerator(AnalyzerParseEventListener.java:154)
        at org.netbeans.modules.web.jspparser.AnalyzerParseEventListener.handleTagBegin(AnalyzerParseEventListener.java:962)
        at org.apache.jasper.compiler.DelegatingListener.handleTagBegin(DelegatingListener.java:221)
        at org.apache.jasper.compiler.DelegatingListener.handleTagBegin(DelegatingListener.java:216)
        at org.apache.jasper.compiler.Parser$Tag.accept(Parser.java:852)
        at org.apache.jasper.compiler.Parser.parse(Parser.java:1145)
        at org.apache.jasper.compiler.Parser.parse(Parser.java:1103)
        at org.apache.jasper.compiler.Parser.parse(Parser.java:1099)
        at org.apache.jasper.compiler.ParserController.parse(ParserController.java:214)
        at org.netbeans.modules.web.jspparser.JspParserImpl.callTomcatParser(JspParserImpl.java:126)
        at org.netbeans.modules.web.jspparser.JspParserImpl.analyzePage(JspParserImpl.java:93)
        at org.netbeans.modules.web.core.jsploader.JspDataObject.createCompiler(JspDataObject.java:297)
        at org.netbeans.modules.web.core.jsploader.JspCompilerSupport.addToJob(JspCompilerSupport.java:62)
        at org.openide.actions.AbstractCompileAction.prepareJobFor(AbstractCompileAction.java:361)
        at org.openide.actions.AbstractCompileAction.createJob(AbstractCompileAction.java:198)
        at org.openide.actions.AbstractCompileAction.compile(AbstractCompileAction.java:209)
        at org.openide.actions.AbstractCompileAction.compileNodes(AbstractCompileAction.java:117)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.openide.actions.ExecuteAction.compile(ExecuteAction.java:225)
        at org.openide.actions.ExecuteAction.execute(ExecuteAction.java:204)
        at org.openide.actions.ExecuteAction.performAction(ExecuteAction.java:102)
        at org.netbeans.modules.web.execution.ExecuteForceReloadAction.performAction(ExecuteForceReloadAction.java:42)
        at org.openide.util.actions.NodeAction$DelegateAction.actionPerformed(NodeAction.java:431)
        at org.netbeans.core.ModuleActions$1.run(ModuleActions.java:97)
        at org.openide.util.Task.run(Task.java:136)
        at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:328)
        at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:670)
>> guys.. the first war file i download can't be run... any idea from the exception below.
which war file?  Is it your own war file or an example war file.

>>index.jsp [-1:-1] java.lang.ExceptionInInitializerError: java.lang.NullPointerException
>>      at org.apache.struts.util.MessageResources.getMessageResources(MessageResources.java:577)
This looks like struts cant find your message resources file.

In struts-config.xml there should be a line like:

    <message-resources parameter="application" null="false"/>

This is telling struts that you have a file called application.properties.  This file should be saved in /WEB-INF/classes





the .war file is from the websites download. the application resource is there. I mean this  <message-resources parameter="application" null="false"/> is there.

And I coded my own struts.. yet again it's stuck in here...

I am using NetBean. Any potential problem you think?


do you have a file called application.properties in the /WEB-INF/classes directory?
>>index.jsp [-1:-1] java.lang.ExceptionInInitializerError: java.lang.NullPointerException

when u get the error, when u start Init. Struts ? or when u run index.jsp ? i think the posible cause is your application.properties don't have the resources required by the index.jsp

for example your index.jsp :

<bean:message key="index.login"/>

but in your application.properties don't have the resource key "index.login"

try to make sure all the required resources is updated in your application.properties, and remember to restart your servlet container after any changes on application.properties.
ok. in my sturt-config.xml file, i specified this line,

<message-resources parameter="ApplicationResources" null="false" />

then in my WEB-INF/classes I also have a file named as

ApplicationResources.properties


KokChoon, this is correct. I call the page through the index.jsp
and this is it:


<%@ taglib uri="struts/bean-el" prefix="bean" %>
<%@ taglib uri="struts/html-el" prefix="html" %>
 
<%@page contentType="text/html"%>
<html>
<head><link href="<html:rewrite page="/rr.css" />" rel="stylesheet" type="text/css" >
    <title><bean:message key="title.employeeform " /> </title>
</head>

<body>
<h1><bean:message key="title.employeeApp" />
</H1>
<html:link page="/do/setupEmployeeForm:>Add Employee </html:link>


<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName"  property="propertyName" /> --%>

</body>
</html>





Your code looks ok...

Which war file did you download?  can you provide the link?
assuming you are talking about rr_lesson_1.war.

How did you deploy the app?  Did you change anything?  What application server are you using?

I have just downloaded the application and deployed it on tomcat.  I am not getting the error you describe.  I just let tomcat deploy the application by copying the jar file to the webapps directory.
some strange on :

1)
<title><bean:message key="title.employeeform " /> </title>

u have a space in "title.employeeform " is it the reason Struts can't find the resource key ? try to change it and test :

<title><bean:message key="title.employeeform" /> </title>

2)
<html:link page="/do/setupEmployeeForm:>Add Employee </html:link>
to
<html:link page="/do/setupEmployeeForm">Add Employee </html:link>

well spotted...  These above are problems however I dont think they are the cause of the problem you described.  Once you fix your initial problem these other 2 problems will become apparant too :)

I still think your application cant find the resources file.   Just try and reseploy the app you downloaded without any changes and work from there...
TQ for correcting me that error. But yet again it's come out.

index.jsp [-1:-1] java.lang.ExceptionInInitializerError: java.lang.NullPointerException
        at org.apache.struts.util.MessageResources.getMessageResources(MessageResources.java:577)
        at org.apache.struts.taglib.html.BaseHandlerTag.<clinit>(BaseHandlerTag.java:108)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:115)

OK. This is the step i used to deploy.
I download the rr_lesson_1.war. And rename again the .war to .zip. Then I unzip it to a folder. After that I tried to mount this folder with my NetBean 3.4.1 development tools. It's using apache tomcat as a application server. But I found this error.

FYI, at first I suspect it's because of the file corrupted or some where got sme bugs. Then I decided to code my own version of the Sturts by following the steps it's mentioned. Yet, same error. Well this 2 version ( 1 download, 1 code my own ) is running on my NetBean.

cool, how can u copy the .jar file into the TOMCAR/web-apps/ folder? i think it's should be the .war file. If I do so, how can be my URL ? where should i set my context-root?

Let's say the physical location is :  tomcat-home-directory/webapps/ rrs_lesson1.war

http://localhost:8081/index.jsp ??

 
how about your web.xml ? check and make sure have this :

  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>application</param-name>
      <param-value>ApplicationResources</param-value>
    </init-param>
    <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>
    <init-param>
      <param-name>validate</param-name>
      <param-value>true</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>

what version of Struts u r using ?
yes. I got that.

<?xml version="1.0" encoding="UTF-8"?>

<!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>
    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>application</param-name>
            <param-value>ApplicationResources</param-value>
        </init-param>
        <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>3</param-value>
        </init-param>
        <init-param>
            <param-name>detail</param-name>
            <param-value>3</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
     </servlet>
   
     <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>/do/*</url-pattern>    
     </servlet-mapping>

    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

    <welcome-file-list>
      <welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>

    <taglib>
        <taglib-uri>struts/bean-el</taglib-uri>
        <taglib-location>/WEB-INF/struts-bean-el.tld</taglib-location>
    </taglib>

    <taglib>
        <taglib-uri>struts/html-el</taglib-uri>
        <taglib-location>/WEB-INF/struts-html-el.tld</taglib-location>
    </taglib>

     <taglib>
        <taglib-uri>struts/logic-el</taglib-uri>
        <taglib-location>/WEB-INF/struts-logic-el.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>jstl</taglib-uri>
        <taglib-location>/WEB-INF/c.tld</taglib-location>
    </taglib>

</web-app>


Struts 1.1

>>l, how can u copy the .jar file into the TOMCAR/web-apps/ folder? i think it's should be the .war file. If I do so, how can be
>>my URL ? where should i set my context-root?

yes it is the .war file not the .jar file, my mistake...

>>Let's say the physical location is :  tomcat-home-directory/webapps/ rrs_lesson1.war

tomcat should extract the .war for you automarically into a directory the same name as the .war.
The url to access it will be:

http://localhost:8081/rrs_lesson1/

(by default tomcats port is 8080, I change mine to 80 so I dont have to set the port in the url)

The problem you are having may be caused by netbeans.  Any chance you can just use tomcat?

What version of tomcat are you using?


tomcat is version 4.0.6

yes. My suspecious is on the netbean. Let me do some testing. But before that mr_cool, my coding and the logic is no problem...

I got all the things that required by the web-sites to do the tutorial. I event can not run the rrs_lesson1.war file. So, dont think it's becasue of my application flow.

I got the latest apache tomcat stable version. Let me try first...

I have tomcat 4.1.27. Do you think it's fine?
Apache Tomcat/4.1.27
[INFO] PropertyMessageResources - -Initializing, config='org.apache.struts.util.
LocalStrings', returnNull=true
[INFO] PropertyMessageResources - -Initializing, config='org.apache.struts.actio
n.ActionResources', returnNull=true
[INFO] PropertyMessageResources - -Initializing, config='org.apache.webapp.admin
.ApplicationResources', returnNull=true
[INFO] Http11Protocol - -Starting Coyote HTTP/1.1 on port 8080
[INFO] ChannelSocket - -JK2: ajp13 listening on 0.0.0.0/0.0.0.0:8009
[INFO] JkMain - -Jk running ID=0 time=0/63  config=C:\Program Files\Apache Group
\Tomcat 4.1\conf\jk2.properties

This error come out... my God....
My tomcat 4.1.27 is working FINE!!!

mr_cool, what version are you running? The nenBean 3.4.1 is using 4.0.6.

:-)

but the above error seems misleading right? org.apache.struts.util returnNull=true....

anyway. TQ!


I mean strust with tomcat 4.1.27 is working fine...
For me, struts is working fine on tomcat 3.2.2 & tomcat 4.1.18 ... :)
Any other recommdation for selecting the prefect IDE for Struts framework?

KokChoon, but how to explain my case? Do you think because of the setting I have set. Logic also...

i never use IDE, coz i feel that is unnecessary (for me). Normally i use Textpad to do all my coding and compile in console, this is easy, u set all your classpath, and u know what is happening... IDE hide all this, of course, it maybe faster, but u will become the "client" of the IDE.

In your case, sorry i don't know about NetBean, but according your testing, seem to be the Netbean cause the problem. I don't think the problem is on tomcat 4.0.6, anyway, u can download and test to prove that is correct.

Just found a url on how to setup struts on NetBean, maybe you can find the answer on it :

http://www.mail-archive.com/struts-user@jakarta.apache.org/msg49612.html

hth.
>> mr_cool, what version are you running? The nenBean 3.4.1 is using 4.0.6.

I am currently running 4.1.27, however I have had struts working on older versions of tomcat too.  I think the problem is probably in the way that netbeans is using tomcat.

>> Any other recommdation for selecting the prefect IDE for Struts framework

I use either JBuilder or eclipse when developing.  However I dont use any of the features they provide specifically for struts.

I avoid using the application server embedded in IDE's, they seem to cause more problems then they solve.  I have found that a stand alone server works best for me.  To speed up your testing you can have tomcat pointing to the same place as your editor.  Just edit the server.xml and add a new <Context>.
mr_cool, I went in to eclipse website before. But I couldn't download any Java IDE. It's only display out this in the Download option.

May I ask which eclipse's IDE you've downloaded?

Kok Choon, when I start picking up Java, i am using Ultraedit. It's some sort like notepad, but little bit advance than notepad. I find it's useful, especially when you are new to i. Like what you said, it'll need me to code everything. But when I need to develop a system, or a complex application, I think using some light-weight IDE is going to help more than you can imagine.

Sorry mr_cool,
when I go into ww.eclipse.org, I choose the Download option on my left. After that I choose the Main Download Sites on the right frame. Then I click the "here" in this statement, "Looking for Tools for PMC click here" .

In the final age,  I only see those tools is for C++, EMF, GEF, Hyades, COBOL only. Nothing for JAVA.

That's why when people start talking they are yusing Eclipse IDE, then I have the same question and same doubt, which IDE they are downloading form the net?

download from here...

http://www.eclipse.org/downloads/index.php

The latest release is 2.11

>> Then I click the "here" in this statement, "Looking for Tools for PMC click here" .

Dont click that..  Just scroll down the page a little more and you will see

Build Type Build Name Build Date
Latest Release 2.1.1 Fri, 27 Jun 2003 -- 15:45 (-0400)
mr_cool, downloading....

TQ for your attention....

TQ!