日期:2014-05-17  浏览次数:20740 次

求救:运行出错了
web.xml代码:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp_ID">
<display-name>myfirstweb</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

welcome.jsp:
<%@ page language="java" contentType="text/html; charset=GB18030"
  pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
(因为我没创建package,所以这里没有import)
<%@request.setCharacterEncoding("GB18030); %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>my first web</title>
</head>
<body>
<%
out.write(Welcome.getWelcome(request.getParameter("user")));
%>
</body>
</html>


Welcome.java:
import java.util.Calendar;

public class Welcome {

public static String getWelcome(String user) {
user = user.trim();
if(user.length()<=0)
user = null;
System.out.println("user=" + user);
String welcome = "欢迎您访问我的第一个WEB网站";
Calendar now = Calendar.getInstance();
if(now.get(Calendar.HOUR_OF_DAY)<12)
welcome = (user == null) ? "早上好," + welcome:user + ",早上好," + welcome;
else if(now.get(Calendar.HOUR_OF_DAY)>=18)
welcome = (user == null) ? "晚上好," + welcome:user + ",晚上好," + welcome;
else if(now.get(Calendar.HOUR_OF_DAY)<18)
welcome = (user == null) ? "下午好," + welcome:user + ",下午好," + welcome;
return welcome;
}
}

在浏览器里打开: http://localhost:8080/myfirstweb,显示如下:


输入字,按提交后就报错了:


请问哪里出错了?求指教

------解决方案--------------------
(因为我没创建package,所以这里没有import)

--> <%@ page language="java" import="Welcome"%> <!-- 你没有包,那你也得把类放进来吧 -->
 

------解决方案--------------------
这个,默认包怎么行呢,类都没导入,怎么能行,自己还是创个包,然后导入吧