Struts problem
Hi friends,
I have installed struts on Apache Tomacat server , but when i compile the package i am getting the following error
Please help me in rectifying the mistake
WEB-INF\src\com\jamesholmes\minihr\SearchForm.java:7:'class' or'interface' exp
ected
import org.apache.struts.action.ActionError;
^
WEB-INF\src\com\jamesholmes\minihr\SearchForm.java:8:'class' or'interface' exp
ected
import org.apache.struts.action.ActionErrors;
^
WEB-INF\src\com\jamesholmes\minihr\SearchForm.java:9:'class' or'interface' exp
ected
import org.apache.struts.action.ActionForm;
^
WEB-INF\src\com\jamesholmes\minihr\SearchForm.java:10:'class' or'interface' ex
pected
import org.apache.struts.action.ActionMapping;
^
4 errors
waiting for ur reply
Thanks in advance
[1245 byte] By [
gania] at [2007-11-26 18:23:40]

# 1
prob ur struts.jar file is missing in the classpath..
# 2
copy all the jar file in the lib folder and try again
# 3
ya the class path is set struts.jar is set in classpath...
gania at 2007-7-9 5:57:42 >

# 4
not only sturts but also all other jars in ur lib folder..
# 5
ya every thing in lib is is set in class path
gania at 2007-7-9 5:57:42 >

# 6
paste ur search form.java code
# 7
Copy the jar files in your WEB-INF/lib folder and then try.
# 8
package com.jamesholmes.struts;
import java.util.List;
import javax.servlet.http.HttpServletRequest;;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class SearchForm extends ActionForm
{
private String name = null;
private String ssNum = null;
private List results = null;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setSsNum(String ssNum) {
this.ssNum = ssNum;
}
public String getSsNum() {
return ssNum;
}
public void setResults(List results) {
this.results = results;
}
public List getResults() {
return results;
}
// Reset form fields.
public void reset(ActionMapping mapping, HttpServletRequest request)
{
name = null;
ssNum = null;
results = null;
}
// Validate form data.
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();
boolean nameEntered = false;
boolean ssNumEntered = false;
// Determine if name has been entered.
if (name != null && name.length() > 0) {
nameEntered = true;
}
// Determine if social security number has been entered.
if (ssNum != null && ssNum.length() > 0) {
ssNumEntered = true;
}
/* Validate that either name or social security number
has been entered. */
if (!nameEntered && !ssNumEntered) {
errors.add(null,
new ActionError("error.search.criteria.missing"));
}
/* Validate format of social security number if
it has been entered. */
if (ssNumEntered && !isValidSsNum(ssNum.trim())) {
errors.add("ssNum",
new ActionError("error.search.ssNum.invalid"));
}
return errors;
}
// Validate format of social security number.
private static boolean isValidSsNum(String ssNum) {
if (ssNum.length() < 11) {
return false;
}
for (int i = 0; i < 11; i++) {
if (i == 3 || i == 6) {
if (ssNum.charAt(i) != '-') {
return false;
}
} else if ("0123456789".indexOf(ssNum.charAt(i)) == -1) {
return false;
}
}
return true;
}
}
gania at 2007-7-9 5:57:42 >

# 9
i have tried everything i:e; copying jar files in my web/inf lib ..
i will also post my struts config file
<?xml version="1.0" ?>
<!DOCTYPE struts-config (View Source for full doctype...)>
- <struts-config>
- <!-- Form Beans Configuration
-->
- <form-beans>
<form-bean name="searchForm" type="com.jamesholmes.minihr.SearchForm" />
</form-beans>
- <!-- Global Forwards Configuration
-->
- <global-forwards>
<forward name="search" path="/search.jsp" />
</global-forwards>
- <!-- Action Mappings Configuration
-->
- <action-mappings>
<action path="/search" type="com.jamesholmes.minihr.SearchAction" name="searchForm" scope="request" validate="true" input="/search.jsp" />
</action-mappings>
- <!-- Message Resources Configuration
-->
<message-resources parameter="com.jamesholmes.minihr.ApplicationResources" />
</struts-config>
gania at 2007-7-9 5:57:42 >

# 10
are u compiling ur source code in command prompt ?
# 11
yes i am compiling my source code in command prompt
gania at 2007-7-9 5:57:42 >

# 12
Y dont u use an IDE or ant to do this for u..
# 13
am sorry i havent used any IDE so far...what could be the mistake? think there is some mistake in installation, but am not able to trace...
gania at 2007-7-9 5:57:42 >

# 14
ok then let us knwo step by step how u are compliing and how u make sure that all your lib/jars are in classpath..regardsShanu
# 15
HI mshanu ,
can u just ask me questions, so tht i can answer u and i think it becomes easy for debugging and tracin where the flaw lies..
actually there was one example given on net so i copied and tried running tht package,, the same application works fine for my friend who tried in hispc... but its not working for me....
The other problem is i am tryin struts forthe first time
gania at 2007-7-9 5:57:44 >

# 16
what is ur server..first tell me that..
# 17
apache tomcat server
gania at 2007-7-9 5:57:44 >

# 18
windows rite?
Ur tomcat server path will be somthing like thi s
d:\tomcat5\webapps\myapplication\web-inf etc..
where my application will be ur application name..and u mite have put allt he jar files inside web-inf\lib
Now create a source file inside web-inf folder..name it as src..create all the java files and packages here..
now go to command prompt and go to the source code location
ie d:\tomcat5\webapps\myapplication\web-inf \src
from here u set the classpath using set classpath=blablabala ..hope u know hw to set classpath properly..
after that execute javac -d d:\tomcat5\webapps\myapplication\web-inf \classes *.java
h
# 19
yes i am exactly following the same prcedure wht u said ... when i do this only i am gettin error..have also posted the source code of my applcation pls check tht also...
gania at 2007-7-9 5:57:44 >

# 20
import javax.servlet.http.HttpServletRequest;;has got two semi colomns...remove that..
# 21
wht a co incidence ...kudos..hurray..
even i tracked the same error..
brilliant ..u r simply great..
thanks for ur support .. thank u very much...
hope u help me to learn struts in a better way in future..
pls give me ur e mail id..
once again thank u very very much for ur support
gania at 2007-7-9 5:57:44 >

# 22
click my id..it shows my email id i guess..
# 23
ha ha.. yes i have sent u a request pls accept...
gania at 2007-7-9 5:57:44 >
