【问题标题】:HTTP Status 404: servlet configuration?HTTP 状态 404:servlet 配置?
【发布时间】:2012-10-07 09:21:51
【问题描述】:

我做了一个 webapp,我想知道我的文件夹的配置以及 web.xml 文件。 webapp 使用 MVC 架构,但我在 apache tomcat 上运行它并没有多大成功。我不知道问题是我构建文件夹的方式,我的 web.xml 文件中缺少某些内容,还是我在我的 jsp 文件中引用它的方式。

举个例子:我在我的jsp文件中引用它的方式是

<form id="loginform" action="/servlet/ControllerServlet" method="post">
<input type="button" onclick="<% response.sendRedirect("/servlet/ControllerServlet?action=register");%>"></input>
<a href="servlet/ControllerServlet?action=upload" id="upload"><span>Upload a profile photo</span></a>

我的文件夹结构是:

newApp(目录) {

newApp/images(目录)

newApp/temp(dir)

newApp/(所有 .jsp 文件)

newApp/WEB-INF(dir){

WEB-INF/web.xml

WEB-INF/lib(目录){

lib/org.apache.commons.jar

WEB-INF/类(目录){

classes/(包括控制器servlet在内的所有类)

我的 web-inf 文件如下所示:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>AssignmentForum</display-name>
    <servlet>
        <description>
        </description>
        <display-name>ControllerServlet</display-name>
        <servlet-name>ControllerServlet</servlet-name>
        <servlet-class>itc357.ControllerServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>ControllerServlet</servlet-name>
        <url-pattern>/ControllerServlet</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

<context-param> 
    <description>Location to store uploaded file</description> 
    <param-name>file-upload</param-name> 
    <param-value>
         c:\apache-tomcat-5.5.29\webapps\data\
     </param-value> 
</context-param>
</web-app>

当我尝试访问jsp页面时tomcat给我的信息是

输入状态报告

消息 /servlet/ControllerServlet

说明请求的资源(/servlet/ControllerServlet)不可用。

为你们能提供的任何帮助干杯,邦迪

【问题讨论】:

  • 可能你的 URL 映射有误?似乎映射到/ControllerServlet 而不是/servlet/ControllerServlet。
  • 试试@Thilo 说的/ControllerServlet

标签: jsp servlets web.xml


【解决方案1】:

你的代码应该是这样的

<script language="javascript">
 function submitForm() {
       document.getElementById("loginForm").submit();
 }
</script>


<form id="loginform" action="/servlet/ControllerServlet" method="post"> 
  <input type="button" onclick="submitForm();"></input> 
          <a href="servlet/ControllerServlet?action=upload" id="upload">
              <span>Upload a profile photo</span>
          </a>
</form>

【讨论】:

    猜你喜欢
    • 2015-10-09
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 2019-07-30
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    • 2012-06-01
    相关资源
    最近更新 更多