回 帖 发 新 帖 刷新版面

主题:我的JSP日历出错,,急急

JSP页面:CanlendarFace.jsp 代码如下:

<%@ pagecontentType="text/html;charset=gb2312"%>
<%@ page language="java" import="java.util.*;java.lang.*" %> 
<%
request.setCharacterEncoding("gb2312");
%>
<html><head><title>JSP日历</title></head>
<body>
<jsp:useBean id="bean" class="swing.CanlendarFace" scope="session"/>

<%

String year, month, date;

        year = request.getParameter("year");

        month = request.getParameter("month");

        date = request.getParameter("date");

        out.println(bean.showHtml(year,month,date));

%>


</body>
</html>

javabean swing.CanlendarFace.java 代码如下:

package swing.CanlendarFace;

import java.util.*;

public class CanlendarFace {
    public String showHtml(String year, String month, String date) {
        int y, m, d;
        GregorianCalendar  temp= new GregorianCalendar ();//取得当前的日历(格里高里历)
        try {
            y = Integer.parseInt(year);
            m = Integer.parseInt(month);
            d = Integer.parseInt(date);
        } catch (Exception e) {           
            y = temp.get(GregorianCalendar.YEAR); //取得年份 ;
            m = temp.get(GregorianCalendar.MONTH); //取的月份
            d = temp.get(GregorianCalendar.DAY_OF_MONTH); //取的当前日
        }
        if (y<1900 ||y>9999) y=temp.get(GregorianCalendar.YEAR); //取得年份 ;
        if (m==-1){
        y--;
        m=11;
        }else if(m==12){
        y++;
        m=0;
        }else if(m<-1 || m>12){
         m = temp.get(GregorianCalendar.MONTH); //取的月份
        }         
        if (d<1 || d>31) d=1;//默认日        
        Calendar thisMonth = Calendar.getInstance();
        thisMonth.set(y, m, d);
        thisMonth.setFirstDayOfWeek(Calendar.SUNDAY);
        thisMonth.set(Calendar.DAY_OF_MONTH, 1);
        int firstIndex = thisMonth.get(Calendar.DAY_OF_WEEK) - 1;
        int maxIndex = thisMonth.getActualMaximum(Calendar.DAY_OF_MONTH);
        String[] days = new String[42];
        for (int i = 0; i < 42; i++) { //初始化表格数据
            days[i] = "&nbsp;";
        }
        for (int i = 0; i < maxIndex; i++) { //初始化具有实际日期值得部分
            days[firstIndex + i] = String.valueOf(i + 1);
        }
        String face = "";
        face += "<table id=\"t1\" width=\"91%\" border=\"1\" align=\"center\" cellpadding=\"2\" cellspacing=\"1\" bordercolordark=\"#94CCF6\" bordercolorlight=\"#fefefe\">";
        face += "<tr>";
        face += "<td height=\"35\" colspan=\"7\" align=\"center\" bgcolor=\"#CAE8FF\">";
        face += "<a href=\"daily.jsp?year="+(y-1)+"&month="+m+"&date=1\">上一年</a>&nbsp;";
        face += "<a href=\"daily.jsp?year="+y+"&month="+(m-1)+"&date=1\">上一月</a>";
        face += "<strong class=\"STYLE4\"> " + y + " 年 " + (m +1) + "  月 </strong>";//"+d +" 日 
        face += "<a href=\"daily.jsp?year="+y+"&month="+(m+1)+"&date=1\">下一月</a>&nbsp;";
        face += "<a href=\"daily.jsp?year="+(y+1)+"&month="+m+"&date=1\">下一年</a>";
        face += "</td></tr>";
        face += "<tr>";
        face += "<td width=\"14%\" align=\"center\" bgcolor=\"#C8E1FA\"><span class=\"STYLE3\">日</span></td>";
        face += "<td width=\"14%\" align=\"center\" bgcolor=\"#C8E1FA\">一</td>";
        face += "<td width=\"14%\" align=\"center\" bgcolor=\"#C8E1FA\">二</td>";
        face += "<td width=\"14%\" align=\"center\" bgcolor=\"#C8E1FA\">三</td>";
        face += "<td width=\"14%\" align=\"center\" bgcolor=\"#C8E1FA\">四</td>";
        face += "<td width=\"14%\" align=\"center\" bgcolor=\"#C8E1FA\">五</td>";
        face += "<td align=\"center\" bgcolor=\"#C8E1FA\"><span class=\"STYLE3\">六</span></td>";
        face += "</tr>";
        for (int j = 0; j < 6; j++) {
            face += "<tr id=\"line"+ j +"\">";
            String status = "status=yes,scrollbars=yes,resizable=yes,width=640,height=480";
            for (int i = j * 7; i < (j + 1) * 7; i++) {
              if (i==35 && days[i].equals("&nbsp;")){
                   face += "<script>line5.style.display=\"none\"</script>";//"<td>&nbsp;</td>";
                   break;
              }
              if (days[i].equalsIgnoreCase(String.valueOf(temp.get(GregorianCalendar.DAY_OF_MONTH)))&& y == temp.get(GregorianCalendar.YEAR) && m == temp.get(GregorianCalendar.MONTH)){
                       face += "<td bgcolor=\"#E7FEE8\" height=\"50\" align=\"center\" <span class=\"STYLE10\">";
              }else if ((i%7)==0 || ((i+1)%7)==0){
                   face += "<td height=\"50\" align=\"center\" <span class=\"STYLE6\">";
              }else{
                   face += "<td height=\"50\" align=\"center\" <span class=\"STYLE7\">";
              }
              face +=  days[i]+"</span>";
                face += "</td>";
            }
            face += "</tr>";
        }
        face += "</table>";
        return face;
    }    
}


运行程序出现如下错误:

The server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: swing/CanlendarFace (wrong name: swing/CanlendarFace/CanlendarFace)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:244)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause 

java.lang.NoClassDefFoundError: swing/CanlendarFace (wrong name: swing/CanlendarFace/CanlendarFace)
    java.lang.ClassLoader.defineClass1(Native Method)
    java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1634)
    org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:860)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1307)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
    org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1214)
    org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

回复列表 (共10个回复)

沙发

javax.servlet.ServletException: swing/CanlendarFace (wrong name: swing/CanlendarFace/CanlendarFace)

没有错的话,你应该是把bean放在swing/CanlendarFace/下
可是你导入的时候<jsp:useBean id="bean" class="swing.CanlendarFace" scope="session"/>
所以改成class="swing.CanlendarFace.CanlendarFace" 看看

板凳

没有,我的bean是放在swing下了..没有下级目录..而且名字等都检查了N遍了...

3 楼

package swing;//这里错了,应该是这样的阿。如果没有CanlendarFace文件夹的话

import java.util.*;

public class CanlendarFace {
    public String showHtml(String year, String month, String date) {
        int y, m, d;
        GregorianCalendar  temp= new GregorianCalendar ();//取得当前的日历(格里高里历)
        try {
            y = Integer.parseInt(year);

4 楼

谢谢yexin218,,
我改了后出现一个新的错误:(去掉swing后面的.CanlendarFace)
description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: Unable to compile class for JSP

Generated servlet error:
D:\Tomcat 5.0\work\Catalina\localhost\myjsp\org\apache\jsp\CanlendarFace_jsp.java:6: 需要为 class、interface 或 enum
import java.util.*;java.lang.*;
                   ^
1 错误



    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
    org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.

5 楼

好了.,,我改了一下,可以运行了..谢谢..谢谢

6 楼

<%@ pagecontentType="text/html;charset=gb2312"%>
<%@ page language="java" import="java.util.*;java.lang.*" %> 
<%@ page import="swing.CanlendarFace" %> 
<%
request.setCharacterEncoding("gb2312");
%>
<html><head><title>JSP日历</title></head>
<body>
<jsp:useBean id="bean" class="swing.CanlendarFace" scope="session">
</jsp:useBean>
<% String year,month,data;//问题在这下面

        year = request.getParameter("year");//你从那里或者这些参数阿?

        month = request.getParameter("month");

        date = request.getParameter("date");

        out.println(bean.showHtml(year,month,date));

%>


</body>
</html>
org.apache.jasper.JasperException: Unable to compile class for JSP

Generated servlet error:
Syntax error on token ";", import expected after this token

An error occurred at line: 12 in the jsp file: /pfancalendar.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens


    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

7 楼

谢谢..我也不明白

8 楼

这个当然是从Bean里吧..那里有输入HTML的语句

9 楼

我只是把这里
JSP页面:CanlendarFace.jsp 代码如下:

<%@ pagecontentType="text/html;charset=gb2312"%>
<%@ page language="java" import="java.util.*;java.lang.*" %> 
后边的;java.lang.*" 去掉,现在就可以运行了,我得仔细看一下这个程序..
我打算自己写个BLOG,用JSP+AJAX

10 楼

我怎么就不行呢?

我来回复

您尚未登录,请登录后再回复。点此登录或注册