1. Use webapps/a/as the Web application directory;
Then drop the following directories and files webapps/a/fbean.jsp
Webapps/a/web-inf/classes/f/a.java
CMD under compile A.java get A.class
<%@ Page ContentType="text/html;charset=gb2312"language="Java"%><HTML><Body><Jsp:usebeanID= "FB"class= "F.A"Scope= "Session" /><%Fb.setfirstproperty ("My First javabean!");%><%=Fb.getfirstproperty ()%></Body></HTML>
fbean.jsp
Package F; Public class A { privatenew String (""); Public A () {} Public void Setfirstproperty (String value) { = value; } Public String Getfirstproperty () { return firstproperty; }}
A.java
Reboot Tomcat to see the effect of localhost:8080/a/fbean.jsp in the browser input
Proof: This JSP and JavaBean are no problem.
2. My f:/code/jsp/myjsp is my Tomcat virtual directory;
Here are the test files that I tested in the virtual directory before, and the related content is as follows:
/* Below is a JSP program that says hello according to time, these files are placed in the same directory, namely test*/
oldhello.jsp a.css hua.png desert.jpg
<%@ page language= "java" pageencoding= "GBK"%> <%@ pageImport= "Java.util.Date"%> <%--java.util Package, dateclass. is old--%><! DOCTYPE html>NewJava.util.Date ()%> <%--show current time like Thu Apr 21:11:20 CST--%>Date x=Newjava.util.Date (); if(X.gethours () >3 && x.gethours () <12) { %> <p style= "color:red; Text-align:center "> Good morning</p> <% }Else if(X.gethours () >12&&x.gethours () <18){%> <p style= "Color:yellow; Text-align:center "> Good afternoon</p> <% }Else if(X.gethours () >18| | X.gethours () <3){%> <p style= "Color:blue; Text-align:center "> Good evening</p> <% } %></body>oldhello.jsp #b {background-image : URL ("Hua.png") ; opacity : 0.4 ; background-repeat : no-repeat ; background-position } #b: hover {: URL ("desert.jpg") ; opacity : 1.0 ; filter : alpha (opacity=100) ; /* for IE8 and earlier */ background-repeat : no-repeat ;}
A.cssIf you look for two pictures, I won't let them go.
The effect can also be displayed after the browser writes the relevant address.
Proof: My virtual directory is fine
3. The problem has come. Since I don't want to put the web directory in a directory created by Tomcat, I've copied everything from 1 to the virtual root. Reboot Tomcat, run an error!
The value for the Usebean class attribute F.A is invalid.These three questions I repeatedly from yesterday page 12 point to try to mistake to this morning 10 point finally solved.
Where my JavaBean code's previous set and get position is wrong, which means that a method is undefined;
Secondly, the correct configuration of the directory structure on the Internet or a variety of problems, so I step by step each time the source file is compiled once, and restart the server. Finally solved.
In addition I found that just change the JSP without restarting the server, directly F5 can.
Another important discovery: I deleted the. class, and F5 still works, and I restarted the server! It's really weird!
But the muddle of the solution will inevitably go wrong. Time is not enough, leave a footprint here.
I moved the A/web-inf web-inf to WebApps under the same directory as a, that is, my virtual directory root directory, run through!
Looks like we're going to have to organize this later.
+ Virtual directory + project directory
+ Project Directory 2
+web-inf
+classes
+ Various packages and classes
I used to think that every project directory with a Web-inf, in the Tomcat installation directory WebApps I do this right. (I just tried to put Web-inf in the project directory!)
However, the JavaBean created under the virtual directory must be located in the Web-inf of the virtual directory root.
JSP and JavaBean virtual directory configuration issues