Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

newbie, execute method not working

 
luckay win
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am very new to struts 2, I am starting my 1st page by just want to to show label "Hello I am here" in my index.jsp via HelloWorld class..
but the execute method not working?

index.jsp


struts.xml


and my HelloWorld.java




 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Is your HelloWorld class in example package??
2. What is the URL that you are entering in the browser??
3. The result configuration says that the result for HelloWorld action is a JSP named HelloWorld.jsp but you've shown us the code for index.jsp. Do you actually have a HelloWorld.jsp in example folder in your application??
4. How do you know the execute method is not getting executed??
 
luckay win
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Is your HelloWorld class in example package?? --> Yes
2. What is the URL that you are entering in the browser?? --> http://localhost:8080/WebApplication3/
3. The result configuration says that the result for HelloWorld action is a JSP named HelloWorld.jsp but you've shown us the code for index.jsp. Do you actually have a HelloWorld.jsp in example folder in your application?? --> No, that's typo ..it should be HelloWorld.jsp

web.xml


4. How do you know the execute method is not getting executed?? --> because I did not see anything in the browser .. it should be "Hello I am here"



please help me to start.. .. thanks
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are accessing the JSP page directly. You'll have to go through the action to see the message. Try the URL http://localhost:8080/WebApplication3/HelloWorld.action
 
luckay win
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
I tried http://localhost:8080/WebApplication3/HelloWorld.action and got the following error message:

HTTP Status 404 - There is no Action mapped for namespace / and action name HelloWorld.

type Status report

messageThere is no Action mapped for namespace / and action name HelloWorld.

descriptionThe requested resource (There is no Action mapped for namespace / and action name HelloWorld.) is not available.
GlassFish Server Open Source Edition 3.0.1


what happen with my struts.xml? or where should I put struts.xml ? .. currently it located under WEB-INF

 
luckay win
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also had checked http://struts.apache.org/2.1.8/docs/simple-setup.html.. and I have exactly the same web application structure

/example/
/example/META-INF/
/example/WEB-INF/
/example/WEB-INF/classes/struts.xml
/example/WEB-INF/lib/
/example/WEB-INF/web.xml
 
Shahriyar Rzayev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well is it problem if we create two jsp pages? It is more attractive
Firts off all your struts.xml file must be located in <default package> in the "source packages" directory.
web.xml must be in WEB-INF directory.
our jsp pages should be in WEB-PAGES directory(it is default) or you may create another folder for it.

So i create two pages index.jsp and helloworld.jsp
index.jsp page simply show a button and asks user to click on it then helloworld.jsp show the message "Hello World i am here".

web.xml file this is:


struts.xml file this is:


the HelloWorld Class :




The index.jsp page:




and the last one helloworld.jsp page:



Thanks
 
luckay win
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks and yes it works with 2 .jsp ..

but still don't understand why it does not work if just 1 .jsp..

 
Shahriyar Rzayev
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
luckay win wrote:Thanks and yes it works with 2 .jsp ..

but still don't understand why it does not work if just 1 .jsp..



maybe with redirection it will possible to do such thing. but 2 pages are better
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic