应该是路径不对,把jsp和目录结构贴出来看看吧。

解决方案 »

  1.   

    从servlet到jsp一般是用重定向还是转发???
      

  2.   

    servlet:import java.io.*;
    import java.io.IOException;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.ServletException;
    import com.bbs.connections.ConnectionFactory;
    import com.bbs.bean.MyQuestionBean;public class MyQuestionServlet extends HttpServlet{public void doGet(HttpServletRequest req,HttpServletResponse res) 
    throws ServletException ,IOException{
                    
                   
                   HttpSession session=req.getSession();
                   String userName=(String)session.getAttribute("userName");
                   
                    int count;
                    Connection conn=null; 
                    Statement stmt=null;
                    ResultSet rs=null;
                    StringBuffer sql=new StringBuffer();
                    ConnectionFactory cf=new ConnectionFactory();
                    try{
                    conn=cf.getConnection();
                    
                    stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
                    sql.append("select * from noteTable where");
                    sql.append(" notewriter='"+userName+"' order by  noteLastTime desc");
                 
                    rs=stmt.executeQuery(sql.toString());
                   
                    MyQuestionBean Mq=new MyQuestionBean();
                    while(rs.next()){
                            Mq.setNoteIDs(Integer.toString(rs.getInt("noteID")));
                     Mq.setNoteTitles(rs.getString("noteTitle"));
                     Mq.setNotePics(rs.getString("notePic"));
                     Mq.setNoteRewriteNums(Integer.toString(rs.getInt("noteRewriteNum")));
                     Mq.setNoteLastTimes(rs.getString("noteLastTime"));
                    }
                    
                    if(conn!=null){
                     conn.close();
                    }
                    
                    req.setAttribute("Mq", Mq);
                    RequestDispatcher rd=getServletContext().getRequestDispatcher("/myquestion.jsp");
                    rd.forward(req,res);
             } catch(SQLException se){
                     System.out.println("SQL error");
                    }
                    }
                    
                    public void doPost(HttpServletRequest req,HttpServletResponse res)
                     throws ServletException,IOException{
                     doGet(req,res);
                    }
            }
            
                    
                    
                    
                    
                    
                    
                    
                     
                     
      

  3.   

    jsp:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <%@ page import="java.util.*" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link href="forum.css" rel="stylesheet" type="text/css">
    <style type="text/css">
    <!--
    .style1 {color: #FFFFFF}
    .style2 {color: #009ACE}
    -->
    </style></head><body>
    <jsp:useBean id="Mq" class="com.bbs.bean.MyQuestionBean" scope="request"/>
    <jsp:useBean id="Util" class="com.bbs.util.MyUtil"/>
     <% String userName=(String)session.getAttribute("userName");%>
     <table width="100%" >
       <tr>
         <td class="postauthor style2">你好<%=userName%>这是你的专家门诊</td>
       </tr>
     </table>
     <table width="100%" height="60" cellpadding="1" cellspacing="1" bgcolor="#000000" >
      <tr>
        <td width="5%" height="25" bgcolor="#009ACE" class="postauthor style1"><div align="center">状态</div></td>
        <td width="72%" bgcolor="#009ACE" class="postauthor style1"><div align="center">主题</div></td>
        <td width="6%" bgcolor="#009ACE" class="postauthor style1"><div align="center">回复</div></td>
        <td width="17%" bgcolor="#009ACE" class="postauthor style1"><div align="center">最后回复时间</div></td>
      </tr>
      
     
    <%
     Vector notes=Mq.getNoteIDs();

     for(int i=0;i<notes.size();i++){

     String noteID=Mq.getNoteIDs(i);
     String noteTitle=Mq.getNoteTitles(i);
     String notePic=Mq.getNotePics(i);
     String noteRewriteNum=Mq.getNoteRewriteNums(i);
     String noteLastTime=Mq.getNoteLastTimes(i);
     
     int RewriteNum=Integer.parseInt(noteRewriteNum);
     noteTitle=Util.ex_chinese(noteTitle);
     noteLastTime=Util.ex_chinese(noteLastTime);
     noteLastTime=(noteLastTime=="")?noteLastTime:noteLastTime.substring(2,15);
     String pic=(RewriteNum==0)?"image/folder.gif":"image/istop.gif";
    %>
      <tr>
        <td height="30" bgcolor="#FFFFFF"><div align="center"><img src=<%=pic%> width="18" height="16">&nbsp;</div></td>
        <td bgcolor="#FFFFFF"><div align="left">  <img src="image/<%=notePic.trim()%>.gif" width="15" height="15"/><a href="note.jsp?noteID=<%=noteID%>"><%=noteTitle%></a>&nbsp;</div></td>
        <td bgcolor="#FFFFFF"><div align="center"><%=noteRewriteNum%>&nbsp;</div></td>
        <td bgcolor="#FFFFFF"><div align="center"><%=noteLastTime%>&nbsp;</div></td>
      </tr>
      <%}%>
    </table></body>
    </html>
      

  4.   

    路径不对,你看看你的url就知道了,url肯定指向那个servlet,因为你用servlet进行了转发,客户端浏览器不知道发生了转发,他认为是还是他请求的url,然后用这个按相对路径去取
    css,按照这个url当然取不到css了.
    你可以考虑用绝对路径,很多网站都这样做的。
      

  5.   

    谢谢楼上的,我在servlet里用了重定向!!!问题解决了!!!