The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

shivkpr (30) [Avatar] Offline
#1
Hi Neal,
<?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-source >
autoCommit="false"
description="DATA BASE CONNEXION"
driverClass="oracle.jdbc.driver.OracleDriver"
maxCount="5"
minCount="1"
password="temp"
url="jdbc:oracle:thin:@lon1:1521:tempa"
user="temp"/>
</data-sources>
<form-beans>
<form-bean name="scheduleItem" >
type="mypackage2.ScheduleItem"
dynamic="no" />
</form-beans>
<action-mappings>
<action >
type="mypackage2.ScheduleItem"
path="/sched">
<forward name="success" path="/ScheduleView.jsp" />
</action>
<action >
type="mypackage2.ScheduleItem"
path="/schedEntry">
<forward name="success" path="/ScheduleEntryView.jsp" />
</action>
<action name="scheduleItem" >
type="mypackage2.ScheduleItem"
validate="true" input="/ScheduleEntryView.jsp"
scope="session" path="/add">
<forward name="success" path="/sched.do" />
<forward name="error" path="/ScheduleEntryView.jsp" />
</action>
</action-mappings>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property >
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>


I know your example covers my-sql. could you advise on the oracle datasource. when i invoke sched.do i just get



Servlet error: Initializing application data source org.apache.struts.action.DATA_SOURCE


Could you please help. many thanks. I have searchd on the web but running out of ideas
nford (36) [Avatar] Offline
#2
Re: Using STruts
This is a tough question because there are so many variables! This is more an Oracle question than a web development one. Here are some things to check:

1) Make sure the Oracle JAR file is on the class path.
2) Verify the user name and password you are using
3) Verify that the server is running on the correct port

I would suggest creating a small console application (or unit test) that tests just the database connectivity to make sure the URL and supporting information is correct. If that works, then you can concentrate on the web tier and look at classpath, load order, and other issues.
shivkpr (30) [Avatar] Offline
#3
Re: Using STruts
Neal,
I think the datasource may now be ok as when I put an invalid password it comes up with the data source issue

With the correct password when I invoke sched.do it just comes up with page not found
My undertanding is that it should invoke
"ScheduleView.jsp"

Anyreason why that cannot be found. I'm using jdeveloper similar to jbuilder. please tell me where i need to setup extra class paths

thanks
nford (36) [Avatar] Offline
#4
Re: Using STruts
You shouldn't need any additional code on your classpath to view the page. Make sure that ScheduleView.jsp is in the root directory.

Also make sure that JDeveloper is placing all the Struts jar files in the WEB-INF/lib folder when it runs the project, and that the classes are getting compiled (or copied) into WEB-INF/class.

Often, this error occurs because the target JSP can't be found. Struts tries to resolve all the forwards before it technically needs to use them, so a page not found usually means that it can't find one of the fowards.
shivkpr (30) [Avatar] Offline
#5
Re: Using STruts
Thanks I'm getting stuck on this one. Chapters prvious to this i have been using jdev and its been fine. finding the jsps
my setup is
strutsex
src
public_html
classes

in public_html I have
the 2 jsps and Web-Inf

In the web-inf folder
I have all the tlds and strut jar files

I created the lib folder within the web-inf and classes folder but nothing gets compiled. j developer does have a libraries section that i have imported all the jars

I hope you can bear with me on this as i find jdeveloper useful to step though the code
nford (36) [Avatar] Offline
#6
Re: Using STruts
OK:

The public_html directory should be set as the web root directory.

The Struts jar files must be in WEB-INF/lib, not just in WEB-INF (any jar file in WEB-INF/lib automatically gets added to the classpath of the web application). The TLDs can stay in WEB-INF. The classes folder contents (maintained by JDeveloper) should be copied to WEB-INF/classes so that the action and other classes can be located.

If you run the ant build file that comes with the project, it should create the correct directory structure for you. You can then convince JD to mimic that structure.
shivkpr (30) [Avatar] Offline
#7
Re: Using STruts
hi I tried to run the ant build file it gives me the following errors
cannot resolve symbol
javax.sql.Datasource in the scheduleentruaction.java


is there a chance to send a simple example with struts just to ensure i can get it going

thanks
ketan
nford (36) [Avatar] Offline
#8
Re: Using STruts
For the ant build file, you are missing the j2ee.jar file from the build path, which I can't re-distribute.

I have attached a very simple Struts project that runs. However, it isn't much simpler than the one in the book! It does not do any database access. Upzip this file into the Webapps (or deployment directory) of you servlet engine, then invoke it with http://localhost:8080/struts1/numbers.do.

Notice the file placement and structure of this example, and replicate it, and you should be able to get the book project to run successfully.
shivkpr (30) [Avatar] Offline
#9
Re: Using STruts
Thanks for this neal but I've tried to setup you sampple in jdeveloper and keep on getting error on

import junit.framework.TestCase;

where do I get this from

Is there anything that i can send you via mail to show my structure
nford (36) [Avatar] Offline
#10
Re: Using STruts
Now you are missing the library files from JUnit, the testing framework. You can download it at www.junit.org.

I can't really do individual debugging on setups that aren't part of the book. I can assit with JBuilder, just an editor, or Eclipse, but I don't really know enough about JDeveloper to give good advice. Most of the problems you have been having have nothing to do with web development, just mundane (but time consuming) classpath issues and setup stuff. Seems like that is always the case in the Java world, especially with open source stuff.
shivkpr (30) [Avatar] Offline
#11
Re: Using STruts
hi,
I'm getting there slowly. TRhe schedule view now gives me

javax.servlet.jsp.JspException: Missing message for key "title.view"
at org.apache.struts.taglib.bean.MessageTag.doStartTag(MessageTag.java:297)

Does the properties file have special naming convention.
I'placed it in the WEB-INF folder.

PLease let me know where I should palce this

thanks
nford (36) [Avatar] Offline
#12
Re: Using STruts
Sounds like you are making good progress.

The properties file that includes all the strings in the project should be on the classpath (in other words, in a directory structure underneath the WEB-INF/classess directory). If you look at the web.xml file on page 141, one of the parameters for the Action servlet is a reference to where this file belongs. The "application" parameter indicates the location on the classpath of the properties file. This means that you should place the Schedule.properties file in WEB-INF/classes/com/nealford/art/strutssched/.

Alternatively, you can specify the location on the classpath with a struts-config parameter, which was introducted in Struts 1.1 (but not mentioned in the book).
shivkpr (30) [Avatar] Offline
#13
Re: Using STruts
HI Neal,
I believe I'm understanding it further. I still have some outstanding issues

- I knoticed when you add an item and try to add another the old details are still present in the form. I presume it does this so incase errors exist can recover old values
However, is there a way to clear the values if no errors ?

Some of the other questions are also listed below

on page 141, what does the debug option offer
what does load-on-startup offer

page 148 did not undestand your comment on schedulebean on session opposed to request. please expand on this

149
In the scheduleEntryView Jsp - How are the errors stored


Formbean - what does the dynamic option do in this context

Now moving onto velocity
Thanks
nford (36) [Avatar] Offline
#14
Re: Using STruts
1. old values
These are present because Struts holds onto the formbean between invocations. If you don't want them to be there, call the reset() method on the form bean after the records is inserted.

2. the debug flag
This flag increases the amount of logging information output by Struts. Typically, you turn this on during development to assist in debugging and turn it off (with a 0 value) for deployment.

3. load on startup
Automatically loads the ActionServlet into memory as the application starts (rather than waiting for the first request). This makes the application startup a little slower but makes the first access of the application faster (because the user doesn't have to wait for the servlet to startup).

4. session vs. request
If the validation attempt fails, the framework redirects the user back to the ScheduleEntryView page. This page must pull the eventTypes from the scheduleBean to populate the select tag. If the scheduleBean was on the request collection, it would fail to load them when the validation failed and the redirection occurred. To see this, change the code in the entry action to place the collection on request instead of session. The first time you see the view page, it works fine, and if you don't have a validation error, it still is fine. However, if you generate a validation error, the page will fail to display because the eventTypes are no longer on the request.

5. error storage
The framework stores the errors in request, and the <html:errors> tags automatically pulls them out. The formBean and the custom tags work together to make this work. You can also store other messages to show up on the page, using addMessages and <html:messages>.

6. Formbean
Dynamic="no" means that this isn't a DynaActionForm, one of the other form types available in Struts, where the form bean is defined entirely within Struts-config (and therefore doesn't have any custom methods, like validate() implemented).

Have fun with Velocity!
shivkpr (30) [Avatar] Offline
#15
Re: Using STruts
HI Neal
I've not touched this for a while due to been busy at work

to get back in touch. i wanted to do a small exercise

My aim is to have an application that selects single column from db, many rows

fetch that into an array

to display - 4 words on each line

entity bean
item1 string
item1 string
item1 string
item1 string


some king of random generator that fetchs from array and sets the items - 4 items per instance


Once the entity bean populated then just display using the JSP. I only want 4 words per line


Is that the righ way, as minimises logic in the jsp


Please let me know your thoughts

Thanks
nford (36) [Avatar] Offline
#16
Re: Using STruts
Yes, I think that is the correct approach. The less code on the JSP, the better.