• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error: Invalid path

 
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I want to pass all jsp files to an action servlet in Struts. I did this.

in web.xml

in struts-config.xml


I have a myfile.jsp in the my own web app root. But the error message is "Invalid path". I don't know why.

Could you help me ? Thanks
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it is looking for saveOK.jsp, which will is getting treated as a Struts ActionMapping because you defined all *.jsp to go to the ActionServlet.
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marc Peabody:
because you defined all *.jsp to go to the ActionServlet.



I still don't understand what would motivate something like that.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try setting the struts debug high enough so you can see what it is looking for or go back and read about how to get it set up to work.

I think it would be confusing to have the url pattern for struts set to *.jsp unless you're not forwarding to *.jsp's.
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Carol Enderlin:
I think it would be confusing to have the url pattern for struts set to *.jsp unless you're not forwarding to *.jsp's.



Aside from being confusing, it won't work unless you're not forwarding to jsp files.
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your guy's responses.

Say this, if in an index.jsp, it will ask the server to do something and then output the dynamic contents. I will do this

-------------------
<jsp:useBean id="layout" class="MyBean" scope="session" />
<% layout.doSomeJob(); %>
<html>... <%= layout.getData(); %>...</html>
--------------------

You see, we have to call directly the bean to create object and get data back. We mix the view and business logic together. I think this is not good MVC patten.

So I try to solve this problem. If user requests a jsp file which has dynamic contents, I sent it to controller, ActionServlet, then the controller gets the path and does its associated business logic, create a result bean and put into sessionScope. after this, forward the request to the jsp file user asked for.

In this way, jsp page just does the present job, no business logic inside.

I want all jsp pages, no matter dynamic and static, to controller, just because I want this design simple.

Now the problem is , the invlid path.
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But you can't forward to a physical jsp file when all *.jsp are sent to the ActionServlet. I don't think you are understanding this.

What is wrong with the conventional *.do?
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marc Peabody:
But you can't forward to a physical jsp file when all *.jsp are sent to the ActionServlet.



I have tried to sent request of index.jsp to ActoinSevlet, and then getPath(), do something, forward to anothe page. It works, I saw the console output. Now the problem is, when it did forwarding, it threw path error.

Originally posted by Marc Peabody:
But you can't What is wrong with the conventional*.do?


Nothing wrong with *.do, but for me, it is not enough. I want jsp files go there , too.

I am a beginer to struts. Thanks for your reply.
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marc, I read your post again.

when I send all jsp file to ActionServlet, it will forward to another jsp page. when Struts see the forwarded jsp page is with *.jsp, it will route this forward back to ActionMapping, then it look up the mapping, there is no path for that page. so it throw invalid path error.

My understanding is right ? This is what you are talking about ?

Before I did some Swing GUI programming, so I always want to use Swing patten to do web app. All actions should go to a central controller.

Now in the web, how could a jsp file only have presentation coding when it has dynamic contents ?

Thank you, Marc.
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Edward Chen:
Marc, I read your post again.

when I send all jsp file to ActionServlet, it will forward to another jsp page. when Struts see the forwarded jsp page is with *.jsp, it will route this forward back to ActionMapping, then it look up the mapping, there is no path for that page. so it throw invalid path error.

My understanding is right ? This is what you are talking about ?


Bingo! You are correct.

By the way, usually an ActionMapping's path does not include the extension as part of the path. (use path="/doSomething", not path="/doSomething.do") In fact, I am not even sure if it works when including the extension.


Before I did some Swing GUI programming, so I always want to use Swing patten to do web app. All actions should go to a central controller.

Now in the web, how could a jsp file only have presentation coding when it has dynamic contents ?


In Swing, each component implements MVC. Mmmmm... so nice.
The MVC for web apps is different. You have to think of each page as one giant component.

When you submit a page, it will update your ActionForm (as you defined it in your ActionMapping) and will send the request along to your Action class (as you defined it in your ActionMapping... com.BookAction for example).
Your Action is then responsible for processing the information submitted and then deciding where to send you next.

You earlier posted:
<jsp:useBean id="layout" class="MyBean" scope="session" />
<% layout.doSomeJob(); %>
<html>... <%= layout.getData(); %>...</html>

That doSomeJob() method, whatever it does, is probably something the Action would take care of.
The getData() is usually something you get from the ActionForm.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The way to think about it is not "forward the user to the Order Form jsp", which puts you in a page-centric mindset. The way to think about it is as an action, such as "Change my view to the order form". When you think in a fashion similar to the latter, it becomes clear that you want your application to perform an action, not merely serve up some jsp page.

So once you've put yourself in the mode of thinking that a user is requesting your application to perform some action, and not merely serve up a JSP page, you might end up with something like the following:

struts-config.xml


myFile.jsp


OR

myFile.jsp


So even though your content int his case is static, you are still going through your controller and simply using a ForwardAction to forward the user to the correct view, instead of having them requesting a jsp directly which would take them outside the realm of your application and its controller.

Now let's say the user fills out our example order form and submits it. They are not submitting to a view, they are submitting to an action. To get in the correct mindset, think that "what do I want to accomplish", not "what do I want to display". What you want to accomplish is processing the order form, a bunch of logic which is handled in an Action class. Incidentally, there may be various consequences of processing your order form which would necessitate any one of a number of views be displayed back to the user.

orderForm.jsp


struts-config.xml


ProcessOrderAction.java


orderOK.jsp


You will see that nowhere is a JSP directly available for request. Every user request is through some Action. In fact, most Struts developers are getting into the habit of placing the JSP files in a directory not accessible by the user directly, often in a subdirectory of /WEB-INF. When you do this, it is impossible for a user to request one of those JSPs directly.

Now in the web, how could a jsp file only have presentation coding when it has dynamic contents ?

If you look at the orderOK.jsp snippet I provided above, you will see that it has dynamic contents as well as only presentation code. Your Action classes make the necessary objects available to the JSP for display, either through an ActionForm, or by placing them into the HttpServletRequest, HttpSession, or ServletContext objects which the JSP can then retrieve the object from.

You might want to think about picking up one of the Struts books. It will probably do a better job communicating to you what we're trying to say, as well as explain the fundamentals that you will need to create successful Struts apps.
[ January 24, 2005: Message edited by: Jason Menard ]
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Jason and Marc.

I will read more about Struts. I really appreciate your help.
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic