我是刚开始的服务器开发,已经从Lars Vogel的easy tutorial开始了。使用Eclipse WTP开发Servlet和JSP。
http://localhost:8080/
显示正确的tomcat页面;DAO
;在这里我看到了下一个提示:
Sep 15, 2013 3:40:39 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Sep 15, 2013 3:40:42 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:com.filecounter' did not find a matching property.
Sep 15, 2013 3:40:43 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Sep 15, 2013 3:40:43 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Sep 15, 2013 3:40:43 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 5203 ms
Sep 15, 2013 3:40:43 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 15, 2013 3:40:43 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
Sep 15, 2013 3:40:45 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [171] milliseconds.
Sep 15, 2013 3:40:46 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Sep 15, 2013 3:40:46 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 15, 2013 3:40:46 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2882 ms
以下是Tomcat/lib
文件夹的内容:
nazar_art@nazar-desctop:/usr/local/tomcat/apache-tomcat-7.0.42/lib$ ls -lg
total 6132
-rwxrwxrwx 1 nazar_art 15264 Jul 2 10:59 annotations-api.jar
-rwxrwxrwx 1 nazar_art 54142 Jul 2 10:59 catalina-ant.jar
-rwxrwxrwx 1 nazar_art 134215 Jul 2 10:59 catalina-ha.jar
-rwxrwxrwx 1 nazar_art 1581311 Jul 2 10:59 catalina.jar
-rwxrwxrwx 1 nazar_art 257520 Jul 2 10:59 catalina-tribes.jar
-rwxrwxrwx 1 nazar_art 1801636 Jul 2 10:59 ecj-4.2.2.jar
-rwxrwxrwx 1 nazar_art 46085 Jul 2 10:59 el-api.jar
-rwxrwxrwx 1 nazar_art 123241 Jul 2 10:59 jasper-el.jar
-rwxrwxrwx 1 nazar_art 599428 Jul 2 10:59 jasper.jar
-rwxrwxrwx 1 nazar_art 88690 Jul 2 10:59 jsp-api.jar
-rwxrwxrwx 1 nazar_art 177598 Jul 2 10:59 servlet-api.jar
-rwxrwxrwx 1 nazar_art 6873 Jul 2 10:59 tomcat-api.jar
-rwxrwxrwx 1 nazar_art 796527 Jul 2 10:59 tomcat-coyote.jar
-rwxrwxrwx 1 nazar_art 235411 Jul 2 10:59 tomcat-dbcp.jar
-rwxrwxrwx 1 nazar_art 77364 Jul 2 10:59 tomcat-i18n-es.jar
-rwxrwxrwx 1 nazar_art 48693 Jul 2 10:59 tomcat-i18n-fr.jar
-rwxrwxrwx 1 nazar_art 51678 Jul 2 10:59 tomcat-i18n-ja.jar
-rwxrwxrwx 1 nazar_art 124006 Jul 2 10:59 tomcat-jdbc.jar
-rwxrwxrwx 1 nazar_art 23201 Jul 2 10:59 tomcat-util.jar
更新:
以下是教程:
在Linux Ubuntu 12.04上安装本机Apache Tomcat
更新2:
public class FileDao {
public int getCount() {
int count = 0;
// Load the file with the counter
FileReader fileReader = null;
BufferedReader bufferedReader = null;
PrintWriter writer = null ;
try {
File f = new File("FileCounter.initial");
if (!f.exists()) {
f.createNewFile();
writer = new PrintWriter(new FileWriter(f));
writer.println(0);
}
if (writer !=null){
writer.close();
}
fileReader = new FileReader(f);
bufferedReader = new BufferedReader(fileReader);
String initial = bufferedReader.readLine();
count = Integer.parseInt(initial);
} catch (Exception ex) {
if (writer !=null){
writer.close();
}
}
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return count;
}
public void save(int count) throws Exception {
FileWriter fileWriter = null;
PrintWriter printWriter = null;
fileWriter = new FileWriter("FileCounter.initial");
printWriter = new PrintWriter(fileWriter);
printWriter.println(count);
// Make sure to close the file
if (printWriter != null) {
printWriter.close();
}
}
}
public class FileCounter extends HttpServlet {
private static final long serialVersionUID = 1L;
int count;
private FileDao dao;
public void init() throws ServletException {
dao = new FileDao();
try {
count = dao.getCount();
} catch (Exception e) {
getServletContext().log("An exception occurred in FileCounter", e);
throw new ServletException("An exception occurred in FileCounter"
+ e.getMessage());
}
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// Set a cookie for the user, so that the counter does not increate
// every time the user press refresh
HttpSession session = request.getSession(true);
// Set the session valid for 5 secs
session.setMaxInactiveInterval(5);
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
if (session.isNew()) {
count++;
}
out.println("This site has been accessed " + count + " times.");
}
public void destroy() {
super.destroy();
try {
dao.save(count);
} catch (Exception e) {
e.printStackTrace();
}
}
}
如何解决这个麻烦?
在java.library.path:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib上找不到
本机库应位于以下位置之一
/usr/java/packages/lib/amd64
/usr/lib64
/lib64
/lib
/usr/lib
而不是在
tomcat/lib
只需为您的平台下载本机库,并将其放置在tomcat所期望的位置中。
请注意,您不需要为开发/测试目的拥有此库。Tomcat没有它也能正常运行。
catalina启动信息:服务器在2882毫秒内启动
如果您在运行servlet时遇到麻烦,那么在run on sever
命令之后,eclipse会打开一个浏览器窗口(embeded(默认)或external(取决于您的配置)。如果浏览器上没有显示任何内容,那么检查浏览器的url栏以查看是否请求了您的servlet。
应该是这样的
http://localhost:8080/<your-context-name>/<your-servlet-name>
编辑2
http://localhost:8080/com.filecounter/FileCounter
<servlet>
<description></description>
<display-name>File counter - My first servlet</display-name>
<servlet-name>file_counter</servlet-name>
<servlet-class>com.filecounter.FileCounter</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>file_counter</servlet-name>
<url-pattern>/FileFounter</url-pattern>
</servlet-mapping>
在eclipse dynamic web project中,默认上下文名与项目名相同。
http://localhost:8080/<your-context-name>/FileCounter
也会奏效的。
HTTP状态404-/ 类型状态报告 消息/ Apache Tomcat/7.0.75 Tomcat Catalina日志和服务器日志都有以下错误: 在java.library.path:/users/luowensheng/library/java/extensions:/library/java/extensions:/network/library/java/extensions:/syst
问题内容: 我正在Windows的Eclipse中使用Tomcat 7。启动Tomcat时,我收到以下信息消息: 在java.library.path中找不到基于APR的Apache Tomcat本机库,该库可在生产环境中实现最佳性能。 这是什么意思,我如何提供APR库? 问题答案: 它的意思完全是它所说的:“在java.library.path中找不到在生产环境中实现最佳性能的基于APR的Apa
服务器xml Tomcat日志 已安装小包 四月一日、三日、九日至五日。el6_2。x86_64 tomcat-7.0.70-2。el6。诺奇 openssl-1.0.1e-48。el6_8.3。x86_64 tomcat-native-1.1.34-1。el6。x86_64 java-1.8.0-openjdk-1.8.0.101-3。b13。el6_8。x86_64 OS:CentOS 如何修
问题内容: 我收到这样的错误消息: Windows无法加载库 名称 库.dll。确保该库位于您的Path环境变量中。线程“主”中的异常java.lang.UnsatifiedLinkError:java.library.path中没有 库名 。 这是我尝试通过cmd在Windows XP上运行jar文件的错误。我想知道java.library.path到底在哪里?我已经将C:\ Program F
这是运行时的stacktrace。存在。 现在,我检查了我的文件夹,在文件路径中有一个 我目前使用的是TomcatV6.0、jre7并安装了JDK1.6.0_34 堆栈跟踪 在java.library.path:C:\Program Files\Java\JRE7\bin;C:\Windows\Sun\Java\bin;C:\Windows\System32;C:\Windows\ICLS客户端\