welcome.java代码:
package welcome;
import javax.servlet;
import javax.servlet.http.*;
import java.util.*;
import java.lang.*
public class welcome {
String welcomestring =new String("欢迎您的光临!!");
Date UseTime=new Date();
public welcome(){
}
public String getwelcomestring()
{
return this.welcomestring;
}
public void setwelcomestring(String welcomestr)
{
this.welcomestring=welcomestr;
}
public String getUserTime()
{
return this.UseTime.toString();
}
public void setUserTime()
{
this.getUserTime();
}
}
welcome.jsp代码:
<jsp:useBean id="wel" scope="application" class="welcome.welcome"/>
<%
if (request.getParameter("welstr")==null)
{
//do nothing
}
else
{
String Tempwelstr=request.getParameter("welstr").toString();
wel.setwelcomestring(Tempwelstr);
}
out.println("<center>");
out.println("JAVA Bean 页面," + wel.getwelcomestring() + "<br>");
out.println("</center>");
out.println("<center>");
out.println("登陆系统的时间" + wel.getUserTime());
out.println("</center>");
%>
错误提示:
500 Servlet Exception
error: File D:\JCreator Pro\MyProjects\welcome.java does not contain type
welcome as expected. Please adjust the class path so that the file does
not appear in the unnamed package.
/welcome.jsp:15: Class welcome not found.
welcome.welcome wel;
^
/welcome.jsp:17: Class welcome not found.
wel = (welcome.welcome) application.getAttribute("wel");
^
/welcome.jsp:19: Class welcome not found.
wel = new welcome.welcome();
^
/welcome.jsp:27: Variable wel may not have been initialized.
out.println("JAVA Bean \u9875\u9762," + wel.getwelcomestring() + "<br>");
^
5 errors
你的.java文件有没有编译成.class文件???
要编译以后才可以用
可能:1。.java文件有没有编译成.class文件
2. .class文件放置的位置不对。设置一下路径
:)
不用编译,你把 .java文件放在resin\doc\web-inf\class\welcome里,运行你的jsp就行了