This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a problem trying to process a form which is inside a jsp page under WEB-INF.
My environment: NetBeans 6.9, GlassFish 3.1, Struts 1.3.8
There are a lot of situations (googling for 2 days) almost like mine but not exactly, this is a link to an example which is almost like mine and it works:
http://netbeans.org/kb/docs/web/quickstart-webapps-struts.html the only difference is that in the example from the above link, the jsp which contains the html:form is outside WEB-INF, but in my case, I have to keep it in WEB-INF and it is not working anymore
After I do everything and I make the deployment, I do the following:
- input the address: http://localhost:8080/MyStrutsApp/loginn and the login form appears
- then I fill in some input, I press Login and I get a 404 Error
Can you please have a look on my code and give some ideas?
- this bean is implemented in package com.myapp.struts; I can list it if you need
darius aron wrote:
the only difference is that in the example from the above link, the jsp which contains the html:form is outside WEB-INF, but in my case, I have to keep it in WEB-INF and it is not working anymore
It is my understanding that nothing under WEB-INF is accessible outside the container in order to protect class files and other resources we don't want users to see. Why is this a requirement?
Thank you for the reply
This is just an example that I am working on so I can understand how to apply the theory in my project. The main thing is that I need to have a form which is inside a jsp under WEB-INF. In my project, the jsp page that contains the form also contains dynamic elements so it must be hidden in WEB-INF, and it will be accessed through the servlet. Do you think how this can be done (html:form inside a jsp under web-inf)? or if it can be done at all in this way?
Yes ofcourse it can be done. You can have all you jsp pages inside WEB-INF and still get it to show. However remember since you cannot access any jsp page inside web-inf directly you need a redirect action to access the pages. The redirect action can be configured in your struts xml. You can also make a mock jsp that will redirect the browser to the action that will in turn redirect it to the jsp. e.g below.
Say your login jsp is called login.jsp
in index.jsp put this
Replace /myproject/MyAction.action with the name of your package/action class
Then in struts.xml map you action to point to login.jsp and you will be all set.
Also another solution
As of the 2.4 version of the Servlet specification you are allowed to have a servlet in the welcome file list. Note that this may not be a URL (such as /myproject/MyAction.action). It must be a named servlet and you cannot pass a query string to the servlet. Your controller servlet would need to have a default action. Hope this helps
Joined: Nov 01, 2010
In web.xml deployment descriptor, it is only ok a mapping like *.something. I also added /loginn which was ok for the beginning because I could load the loginn.jsp page. But after that I was asking from the html:form, for the action named "/login" which was matching the second pattern (because it ALWAYS matches the last pattern) which begins with "/" and it didn't go for "*.do" and after that everything was a mess.
So, the solutions would look like this: