当前位置: 技术问答>java相关
帮我看一下这个编译问题
来源: 互联网 发布时间:2017-04-18
本文导语: 以下这个程序 import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class SessionExample extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOExcepti...
以下这个程序
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionExample extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(true);
// print session info
Date created = new Date(session.getCreationTime());
Date accessed = new Date(session.getLastAccessedTime());
out.println("ID " + session.getId());
out.println("Created: " + created);
out.println("Last Accessed: " + accessed);
// set session info if needed
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
// print session contents
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println(name + " = " + value);
}
}
}
---------------------------------------------------------
javac 时报错
错误是
package javax.servlet does not exist
import java.servlet.*;
但是我运行http://localhost:8080时
时自带的index.html文件中jsp和servlet例子我都能运行啊
还有一点是我找不到它自带的比如HelloWorldExample.class
这个文件
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionExample extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(true);
// print session info
Date created = new Date(session.getCreationTime());
Date accessed = new Date(session.getLastAccessedTime());
out.println("ID " + session.getId());
out.println("Created: " + created);
out.println("Last Accessed: " + accessed);
// set session info if needed
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
// print session contents
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println(name + " = " + value);
}
}
}
---------------------------------------------------------
javac 时报错
错误是
package javax.servlet does not exist
import java.servlet.*;
但是我运行http://localhost:8080时
时自带的index.html文件中jsp和servlet例子我都能运行啊
还有一点是我找不到它自带的比如HelloWorldExample.class
这个文件
|
resin默认配置会自动编译,在classpath中要加入包javax.servlet所在的jar文件才可以用javac.你找不到它自带的.class有可能是还没有编译.
|
主要就是这个servlet.jar包没有包含到classpath里的问题
直接将servlet.jar放入[x]:resinlib,然后在classpath包含这个包的路径就行了,ok??
直接将servlet.jar放入[x]:resinlib,然后在classpath包含这个包的路径就行了,ok??
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。