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.
1.I want to trigger an Action without a HTML form, but the struts config must use an ActionForm for an Action, How I could do that? 2.I found if I use Struts in my project, the JSP's EL can't use, but sometimes I must use it, How to fix it, or Is there another way? 3.I want to fill the HTML form with the value I retrieve from database, How can I do that with struts?
1.I want to trigger an Action without a HTML form, but the struts config must use an ActionForm for an Action, How I could do that?
Struts is a "Web application Framework", which means that it it's for creating applications that use HTTP requests for triggering actions. If you want something else to trigger your actions, you may need to find that functionality in another tool or framework. Just out of curiosity, what do you want to trigger your actions?
2.I found if I use Struts in my project, the JSP's EL can't use, but sometimes I must use it, How to fix it, or Is there another way?
Using Struts does not disable EL. Any 2.4 web container will still support the use of EL regardless of whether you use Struts or not. Check the top of the web.xml file in your Struts application. I suspect that it may be using the DTD for Version 2.3 of the Servlet Spec, rather than 2.4. Since 2.3 doesn't support EL except inside JSTL tags, this may be the reason your EL isn't working.
3.I want to fill the HTML form with the value I retrieve from database, How can I do that with struts?
If you will put the information you retrieve from a database into a javaBean that extends ActionForm and assign that bean to the action in the struts-config.xml file, Struts will populate the form automatically for you as long as you use the Struts <html:xxx> tags in the JSP that calls the action.
For example, if you have a CustomerForm bean with a property of customerName, Struts will display whatever is in that property if you code <html:text property="customerName" /> in your JSP.
1.Maybe I explained poorly, I want to trigger the action with a hyperlink, I do a do that without a ActionForm. 2.I use Tomcat 5.0, I think It's suppport EL, but I only can use EL automatically without Struts, with Struts, I must explicit direct in page direction that I want to use it.
You can call an action through a hyperlink. That is a very common practice. If your action does not need an Action form, just leave off the "name=" entry of your action definition (the form parameter of your execute method will be null).
Depending on what you are doing, it may make sense to associate a form to your Action. For example, I might have three related actions: AddUser, EditUser and SaveUser. I would declare each of these to use the form UserForm. From a page that displays a list of users, I might have a hyperlink that looks like "../EditUser.do?id=25". The execute method would get passed a UserForm with the id property populated. I would use the id from the form to lookup the user and then I would populate the UserForm with the data retrieved.
I have not done enough with EL to weigh in on that topic.