• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

html:form not working if it is inside a jsp under WEB-INF

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
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?

MyStrutsApp/WEB-INF/loginn.jsp:


MyStrutsApp/WEB-INF/success.jsp:



MyStrutsApp/WEB-INF/web.xml:


MyStrutsApp/WEB-INF/struts-config.xml:



LoginForm.java

- this bean is implemented in package com.myapp.struts; I can list it if you need

LoginAction.java


GetAction.java



 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
darius aron
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 14
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

web.xml


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
 
darius aron
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally Solved!!!
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:

1.


or

2.

and another adjustments in the Action Class
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic