JSP configured virtual directory using JavaBean error

Source: Internet
Author: User

Today encountered a very difficult problem, in the JSP file using Usebean, the page return code 500 server Internal error, the error message is as follows:

The value for the Usebean class attribute WP. A is invalid.

Before the project was placed in Tomcat's WebApps folder, the operation was normal, and now the virtual directory is configured, so it is not related to JavaBean, it should be associated with the configuration of the virtual directory

Try a lot of methods are useless, and finally found the right solution (workaround at the bottom, if you use JavaBean can skip the middle part directly)

Before doing this, let's start by introducing how to use JavaBean in the JSP of a new project under the Tomcat WebApps folder.

1. Create a new Java file, for example:

 package WP;  public  class   A { private  String firstproperty = new  String (  public   A () {}  public  void   Setfirstproperty (    String value {firstproperty  = value;         public   String Getfirstproperty () {     return   Firstproperty; }}

Note: At least one parameterless constructor should be included in the JavaBean

2. Create the web-inf folder in the root directory of the project (case-sensitive, not wrong)

3. Create the Classes folder under the Web-inf folder (the name is fixed)

4. Under the Classes folder, create a folder with the package followed by the name in the Java file (example, the packages named WP)

5. Compile the written Java file and put the generated . class file under the final package (WP)

6. Finally use the following code in the JSP file JavaBean

<jsp:usebean id="a"class="WP. A" scope="page" />

Parameter explanation: The ID is the name of the JavaBean to be referenced, the value of class is the location of the JavaBean class file (not followed by the. Class), scope is set the bean's valid range (life cycle), currently set is only valid on this page

Call of JavaBean

Using methods defined in JavaBean by A.setxxx ("") and A.getxxx ()

Finally, this is the focus of this article, about configuring the virtual directory (not configured to self-search), using JavaBean error

It is simple to set up the Web-inf folder in the root directory of the configured virtual directory

(If the virtual directory is D:\workspace to create a personal project under this file named demo, it is common practice to set the Web-inf folder directly under the demo, which is wrong, but needs to be established in the root directory of workspace)

JSP configured virtual directory using JavaBean error

Related Article

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.