当前位置: 技术问答>java相关
高手指点,初学者问题。在线等待。
来源: 互联网 发布时间:2017-04-30
本文导语: 我有两个类药编译,这两个文件是HTMLTable.java和RequestResponseServlet.java, 其中RequestResponseServlet中用到HTMLTable类,编译HTMLTable时通过,编译RequestResponseServlet.java时出现如下错误,请问这是为什么? C:Tomcat 4.1webappsservletAPIs...
我有两个类药编译,这两个文件是HTMLTable.java和RequestResponseServlet.java, 其中RequestResponseServlet中用到HTMLTable类,编译HTMLTable时通过,编译RequestResponseServlet.java时出现如下错误,请问这是为什么?
C:Tomcat 4.1webappsservletAPIservletsbasicServlets>javac RequestResponseServlet.java
RequestResponseServlet.java:48: cannot resolve symbol
symbol : class HTMLTable
location: class basicServlets.RequestResponseServlet
HTMLTable table = new HTMLTable();
^
RequestResponseServlet.java:48: cannot resolve symbol
symbol : class HTMLTable
location: class basicServlets.RequestResponseServlet
HTMLTable table = new HTMLTable();
^
RequestResponseServlet.java:130: cannot resolve symbol
symbol : class HTMLTable
location: class basicServlets.RequestResponseServlet
HTMLTable table = new HTMLTable();
^
RequestResponseServlet.java:130: cannot resolve symbol
symbol : class HTMLTable
location: class basicServlets.RequestResponseServlet
HTMLTable table = new HTMLTable();
HTMLTable.java如下:
package BasicServlets;
public class HTMLTable
{
private StringBuffer head;
private StringBuffer rows;
private StringBuffer foot;
public HTMLTable()
{
head = new StringBuffer();
head.append("");
head.append("Attribute");
head.append("Value");
rows = new StringBuffer();
foot = new StringBuffer();
foot.append("");
}
public void appendTitleRow(String attribute)
{
rows.append("").append(attribute);
rows.append("");
}
public void appendRow(String attribute, String value)
{
rows.append("").append(attribute);
rows.append("").append(value).append("");
}
public void appendRow(String attribute, int value)
{
appendRow(attribute, new Integer(value).toString());
}
public void appendRow(String attribute, boolean value)
{
appendRow(attribute, new Boolean(value).toString());
}
public String toString()
{
return head.append(rows).append(foot).toString();
}
public StringBuffer toStringBuffer()
{
return head.append(rows).append(foot);
}
}
RequestResponseServlet.java如下:
package basicServlets;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class RequestResponseServlet extends GenericServlet
{
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException
{
StringBuffer requestTable = getRequestTable(request);
StringBuffer responseTable = getResponseTable(request, response);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("RequestResponseServlet");
out.println("Request Information" + requestTable + "");
out.println("Response Information" + responseTable);
out.println("");
out.close();
}
private StringBuffer getRequestTable(ServletRequest request)
{
HTMLTable table = new HTMLTable();
table.appendTitleRow("Parameters");
Enumeration e = request.getParameterNames();
while (e.hasMoreElements())
{
String paramName = (String)e.nextElement();
String[] paramValues = request.getParameterValues(paramName);
if (paramValues != null)
{
for (int i = 0; i
C:Tomcat 4.1webappsservletAPIservletsbasicServlets>javac RequestResponseServlet.java
RequestResponseServlet.java:48: cannot resolve symbol
symbol : class HTMLTable
location: class basicServlets.RequestResponseServlet
HTMLTable table = new HTMLTable();
^
RequestResponseServlet.java:48: cannot resolve symbol
symbol : class HTMLTable
location: class basicServlets.RequestResponseServlet
HTMLTable table = new HTMLTable();
^
RequestResponseServlet.java:130: cannot resolve symbol
symbol : class HTMLTable
location: class basicServlets.RequestResponseServlet
HTMLTable table = new HTMLTable();
^
RequestResponseServlet.java:130: cannot resolve symbol
symbol : class HTMLTable
location: class basicServlets.RequestResponseServlet
HTMLTable table = new HTMLTable();
HTMLTable.java如下:
package BasicServlets;
public class HTMLTable
{
private StringBuffer head;
private StringBuffer rows;
private StringBuffer foot;
public HTMLTable()
{
head = new StringBuffer();
head.append("");
head.append("Attribute");
head.append("Value");
rows = new StringBuffer();
foot = new StringBuffer();
foot.append("");
}
public void appendTitleRow(String attribute)
{
rows.append("").append(attribute);
rows.append("");
}
public void appendRow(String attribute, String value)
{
rows.append("").append(attribute);
rows.append("").append(value).append("");
}
public void appendRow(String attribute, int value)
{
appendRow(attribute, new Integer(value).toString());
}
public void appendRow(String attribute, boolean value)
{
appendRow(attribute, new Boolean(value).toString());
}
public String toString()
{
return head.append(rows).append(foot).toString();
}
public StringBuffer toStringBuffer()
{
return head.append(rows).append(foot);
}
}
RequestResponseServlet.java如下:
package basicServlets;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class RequestResponseServlet extends GenericServlet
{
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException
{
StringBuffer requestTable = getRequestTable(request);
StringBuffer responseTable = getResponseTable(request, response);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("RequestResponseServlet");
out.println("Request Information" + requestTable + "");
out.println("Response Information" + responseTable);
out.println("");
out.close();
}
private StringBuffer getRequestTable(ServletRequest request)
{
HTMLTable table = new HTMLTable();
table.appendTitleRow("Parameters");
Enumeration e = request.getParameterNames();
while (e.hasMoreElements())
{
String paramName = (String)e.nextElement();
String[] paramValues = request.getParameterValues(paramName);
if (paramValues != null)
{
for (int i = 0; i
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。