Label application is more complicated

zhaozj2021-02-16  59

I saw someone in the community today, and I also encountered similar questions:

JSP file:

<% @ Page ContentType = "Text / HTML; Charset = GBK"%> <% @ Taglib Uri = "/ Web-INF / STRUTS-Bean.tld" prefix = "bean"%>

Exaction.java:

Package web;

Import org.apache.struts.action. *; import javax.servlet.http. *;

public class exAction extends Action {public ActionForward execute (ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {exActionForm exActionForm_1 = (exActionForm) actionForm; if (! exActionForm_1 = null) {String test = exActionForm_1.getTest (); httpServletRequest. SetAttribute ("Test", Test);} else httpservletRequest.setttribute ("test", "fail"); Return (ActionMapping.FindForward ("Success");}}

ExactionForm.java:

Package web;

Import org.apache.struts.action. *; import javax.servlet.http. *;

Public class exactionform extends an actionform {public actionerrors validate (ActionMapping actionMapping, httpservletRequest httpservletRequest) {

Return NULL;

PRIVATE STRING TEST;

PUBLIC STRING Gettest () {Return this.test;}

Public void settest (string test) {this.test = test;} public void reset (actionMapping actionmapping, httpservletRequest httpservletRequest) {}}}}

Struts-config.xml:

http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd ">

-------------------------------------------------- -------- Why didn't I go to an ExactionForm object? ? EXACTIONFORM_1 always null? ? ?

reply as below:

Very simple, a large number of Struts, which is the same as my mistake, it is easy to lead to this issue in beginners.

Note that form action = "exaction.do" in JSP should be = "/ exaction / exaction.do, if your application directory is exaction

If used

There is no problem with the mark

Unfortunately, in any material can't find the conversion function of the tag library to the path, only the source code is learned.

Just find:

Action application is complicated:

Form mark

The tag is used to display the HTML tag, which can specify the name of the AcitonForm Bean and its class name. If these properties are not set, you need to have a configuration file to specify an actionMApping to indicate which JSP page currently entered, and the Bean name and class retrieved from the map. If you do not find the specified name in the scope specified by ActionMapping, you will create and store a new bean, otherwise the found bean will be used.

转载请注明原文地址:https://www.9cbs.com/read-15550.html

New Post(0)