JRun工作......如何在jrun服务器中使用servlet

时间:2022-02-15 18:22:46

JSP pages are correctly working in Jrun, but when I used servlet it cannot find .class file of that servlet and gives 404 error while execution. Can any one help me how jrun works with servlet? Am I missing out any point?

JSP页面在Jrun中正常工作,但是当我使用servlet时,它无法找到该servlet的.class文件,并在执行时出现404错误。任何人都可以帮助我jrun如何与servlet一起工作?我错过了任何一点吗?

here is my web.xml

这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>myProject</display-name>

      <servlet>
        <description></description>
        <display-name>myClass</display-name>
        <servlet-name>myClass</servlet-name>
        <servlet-class>myPackage.myClass</servlet-class>

      </servlet>
      <servlet-mapping>
        <servlet-name>myClass</servlet-name>
        <url-pattern>/myClass</url-pattern>
      </servlet-mapping>
    </web-app>

and my simple servlet

和我简单的servlet

package myPackage;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

public class myClass extends HttpServlet {
    private static final long serialVersionUID = 1L;


        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter pw = response.getWriter();
        pw.println("<html><body>my page</body></html>");
    }

}

and jsp page

和jsp页面

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="myClass" method="post">
<input type="submit" value="submit">
</form>
</body>
</html>

2 个解决方案

#1


0  

I admit, I've never worked with JRun... I think you should take a look on your WAR (you're supposed to compile your code into war or directory. Search there whether you have your binary compiled servlet file (it should be myClass.class)

我承认,我从未使用过JRun ...我认为你应该看看你的WAR(你应该将你的代码编译成war或目录。在那里搜索你是否有你的二进制编译的servlet文件(它应该是myClass.class)

#2


0  

I got the solution. It gave error due to DOcTYPE declaration.. I just replace my web.xml with

我得到了解决方案。由于DOcTYPE声明它给出了错误..我只是用我的web.xml替换

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- ... -->
<servlet>
<servlet-name>myClass</servlet-name>
<servlet-class>myPackage.myClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myClass</servlet-name>
<url-pattern>/myClass</url-pattern>
</servlet-mapping>
<!-- ... -->
</web-app>

#1


0  

I admit, I've never worked with JRun... I think you should take a look on your WAR (you're supposed to compile your code into war or directory. Search there whether you have your binary compiled servlet file (it should be myClass.class)

我承认,我从未使用过JRun ...我认为你应该看看你的WAR(你应该将你的代码编译成war或目录。在那里搜索你是否有你的二进制编译的servlet文件(它应该是myClass.class)

#2


0  

I got the solution. It gave error due to DOcTYPE declaration.. I just replace my web.xml with

我得到了解决方案。由于DOcTYPE声明它给出了错误..我只是用我的web.xml替换

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- ... -->
<servlet>
<servlet-name>myClass</servlet-name>
<servlet-class>myPackage.myClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myClass</servlet-name>
<url-pattern>/myClass</url-pattern>
</servlet-mapping>
<!-- ... -->
</web-app>