File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Hi 'm strugling lot to run a simple hello world prgm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Hi Watch "Hi New topic
Author

Hi 'm strugling lot to run a simple hello world prgm

manikandan jayakumar
Ranch Hand

Joined: Aug 20, 2011
Posts: 41

These are my files:
Index page: (proj/)

web.xml: (proj/WEB-INF/)

struts-config.xml: (proj/WEB-INF/)



helloWorld.jsp (proj/pages/)

helloWorld.java: (proj/WEB-INF/classes/com/salsa/)

'm trying this for 3 days

i got the index page with a button"submit" if i click on it:

"Error the requested resource (/helloWorld)is not available."

Can anyone help me to execute this prgm. it would be a grt help for me
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

1. I don't see the XML declaration in your web.xml.
2. Your HelloWorld class is an action not a servlet, you should map ActionServlet in your web.xml and not your own class.
3. The ActionServlet is generally mapped to *.do extension in web.xml.
4. Your form would not submit to /helloWorld (unless you are deploying your application on ROOT path. You should add a ${pageContext.request.contextPath} before it so that it will contain the context path. So your form should submit to something like /proj/helloWorld.do (assuming proj is the context path)


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
manikandan jayakumar
Ranch Hand

Joined: Aug 20, 2011
Posts: 41

Did the changes in web.xml

hope its correct. But i cant get the 4th point of your reply post.
can you explain it? please
manikandan jayakumar
Ranch Hand

Joined: Aug 20, 2011
Posts: 41

I have included the code

to my execute method of action class so that i may check whether the control is reaching this method
and executed the code same error and not getting the out.txt file too; its not working

So the prob would be with form tag and action mapping.
Orton K Randy
Ranch Hand

Joined: Aug 12, 2011
Posts: 41

What's the URL you see in your address bar?
Like,
http://hostname:port/proj/helloworld

or
http://hostname:port/helloworld

It all depends on your action attribute of form element in your JSP. If it doesn't contain a leading '/', the former would result. On the contrary, if it does contain a leading '/', the latter would result, which isn't obviously the desired one. I'd advise you to use

in your JSP.

Also you don't need to write to a file for checking if a section of code is reached, you could use Sysouts, loggers or even debug with IDE.


Coderanch, best ever forum on the net. Hands down.
manikandan jayakumar
Ranch Hand

Joined: Aug 20, 2011
Posts: 41

index.jsp


strutr-config.xml


now also getting error
"The server encountered an internal error () that prevented it from fulfilling this request."
javax.servlet.ServletException: org.apache.struts.chain.commands.InvalidPathException: No action config found for the specified url.
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Orton K Randy
Ranch Hand

Joined: Aug 12, 2011
Posts: 41

What URL do you see in the address bar again? If it is:
http://hostname:port/proj/helloWorld.do


then the error simply means the actionmapping for /helloWorld is missing in the struts-config.xml(or it can't find the struts-config.xml at all). You could check that by getting rid of the form from the JSP altogether and simply having a single link to trigger the action, like:
assuming you declared
and have the necessary JARs in place.

Start with how to build Struts applications in case you're not confident of proceeding.

manikandan jayakumar
Ranch Hand

Joined: Aug 20, 2011
Posts: 41

Thanks a lot Randy
I got the output by your guidance.
thanks a lot now 'm going to extend the proj to get stud details.
Orton K Randy
Ranch Hand

Joined: Aug 12, 2011
Posts: 41

Glad that I could help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hi 'm strugling lot to run a simple hello world prgm
 
Similar Threads
Servlet Action not found
newbie, execute method not working
404 Error
servlet action is not available
Once more: javax.servlet.jsp.JspException: Cannot find bean