0

我做了一个 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/(所有 .jsp 文件)

newApp/WEB-INF(目录){

WEB-INF/web.xml

WEB-INF/lib(目录){

lib/org.apache.commons.jar

WEB-INF/类(目录){

类/(所有类,包括控制器 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) 不可用。

为你们能给予的任何帮助欢呼,邦迪

4

1 回答 1

0

你的代码应该是这样的

<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>
于 2012-10-17T09:18:11.537 回答