A bug caused by an image of Struts2, struts2bug

Source: Internet
Author: User

A bug caused by an image of Struts2, struts2bug

Open a project as usual today. Write for a while to save the test. An error occurred while logging on. Ah, yesterday was good. Starting to find bugs

The core error code is as follows:

10:34:46, 442 WARN OgnlValueStack: 60-Error setting expression 'login. X' with value' [Ljava. lang. String; @ 5e7b8281'
Ognl. OgnlException: target is null for setProperty (null, "x", [Ljava. lang. String; @ 5e7b8281)

10:34:46, 445 WARN OgnlValueStack: 60-Error setting expression 'login. Y' with value' [Ljava. lang. String; @ 221aa7c1'
Ognl. OgnlException: target is null for setProperty (null, "y", [Ljava. lang. String; @ 221aa7c1)

If a type conversion error is reported, NO x or y parameter exists in the root of the Action.

Later, I saw that some of my predecessors encountered the same problem on a web site. Solution: (check whether there is an image and whether the image has a name attribute. If so, delete the image.

The following is a reprinted predecessor's description:

The Struts2 exception occurs when the form is submitted. At first glance, it is thought to be a Struts2 type conversion error, but the Struts2 type conversion is not used at the root of the program, and the index on the front-end page. the parameters x and y are not set in jsp, and this error does not affect the normal operation of the program. It has been found for a long time, and the final result is the submission button, the submit button references an image as follows:

<Input id = "submit" type = "image" name = "ssc" src = "asserts/images/5.jpg"/>

Because the name attribute is set in Form submission, struts2 receives the corresponding value and searches for its set and get methods. The action does not have this name value, so the above error occurs. You can write as follows:
<Input id = "submit" type = "image" src = "asserts/images/5.jpg"/>
Remove the name attribute.
In fact, you can configure the "struts. devMode" attribute in the struts. xml file.
When struts. when devMode is set to true, use struts to force the setter method to any parameter submitted to action in the default configuration, when there is a parameter name that does not match the action attribute in the html form data, such information is displayed. Therefore, it is good to set this attribute to true during the development process. It helps us find some problems that may occur but are ignored by us. The more "errors" we make, can accumulate a lot of experience

Reference: http://fanli7.net/a/JAVAbiancheng/Struts/20140329/485364.html


An inexplicable error message appears when a newbie configures Struts2.

Obviously, ResourceNotFoundException cannot find the template. vm file.
The general solution is to specify the template path and call this template file during velocity initialization. This solves the problem. If you specify the path, it is very likely that the path is incorrect and the absolute path and relative path are not clear.
If so:
Template = this. getTemplate ("VM_global_library.vm ");
Then VM_global_library.vm should be placed in the root directory of your project.
If:
Template = this. getTemplate ("abc/VM_global_library.vm ");
Welcome. vm where your project is located is abc/VM_global_library.vm under the WEB-INF.
Example:
VelocityEngine ve = new VelocityEngine ();
Properties properties = new Properties ();
String basePath = "src/com/worthtech/app/test ";
// Write the path here !!!
// Set the template path
Properties. setProperty (Velocity. FILE_RESOURCE_LOADER_PATH, basePath );
// Initialize velocity to make the set path take effect
Ve. init (properties );
/* Next, get the Template */
Template t = ve. getTemplate ("vm. vm ");
/* Create a context and add data */
VelocityContext context = new VelocityContext ();
......




Hello World HTTP 404 error in the first program of struts2

You have not created an action. Try to create a XXAction. class file and write a method. The default method (overwritable) is execute:

Public string execute (){
System. out. println ("successful! ");
Return "results"; // specify the jump method, which is specified in the configuration file.
}

Modify struts. xml:
// Class: Specifies
<Action name = "hello" class = ".../XXAction. class">
<Result name = "results"> (full path is recommended here)/Hello. jsp </result>
</Action>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.