我正在开发一个Web应用程序,但是当我尝试运行welcome.html并单击AddActor按钮时,它会指向一个将数据发布到servlet的表单。当我试图运行时,我收到此错误,请帮助我
我正在使用sts,tomcat 8,maven web app
我的目录结构如下
welcome.html
<!doctype html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Film Management System</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="login.css">
<script type="text/javascript" src="../script/angular.min.js"></script>
<script type="text/javascript" src="../script/angular-route.min.js">></script>
<script type="text/javascript" src="../script/appConfig.js"></script>
<script type="text/javascript" src="../script/appCtrl.js"></script>
</head>
<body ng-app="myApplication">
<img src='../static/bg.png' width="1280" height="222"/>
<div ng-controller="myCtrl">
<a href="#/AddNewFilm" class="addfilm_buttton button1" ng-click="action.addFilm()" ng-hide="action.buttonClicked.addFilm || action.buttonClicked.modifyFilm || action.buttonClicked.searchFilm || action.buttonClicked.removeFilm || action.buttonClicked.getAllFilms || action.buttonClicked.addActor || action.buttonClicked.modifyActor || action.buttonClicked.searchActor || action.buttonClicked.removeActor || action.buttonClicked.getAllActors">Add film</a>
<a href="#/ModifyFilm" class="modifyfilm_buttton button1" ng-click="action.modifyFilm()" ng-hide="action.buttonClicked.addFilm || action.buttonClicked.modifyFilm || action.buttonClicked.searchFilm || action.buttonClicked.removeFilm || action.buttonClicked.getAllFilms || action.buttonClicked.addActor || action.buttonClicked.modifyActor || action.buttonClicked.searchActor || action.buttonClicked.removeActor || action.buttonClicked.getAllActors">Modify Film</a>
<a href="#/ModifyFilm" class="searchfilm_buttton button1" ng-click="action.searchFilm()" ng-hide="action.buttonClicked.addFilm || action.buttonClicked.modifyFilm || action.buttonClicked.searchFilm || action.buttonClicked.removeFilm || action.buttonClicked.getAllFilms || action.buttonClicked.addActor || action.buttonClicked.modifyActor || action.buttonClicked.searchActor || action.buttonClicked.removeActor || action.buttonClicked.getAllActors">Search Film</a>
<a href="#/ModifyFilm" class="removefilm_buttton button1" ng-click="action.removeFilm()" ng-hide="action.buttonClicked.addFilm || action.buttonClicked.modifyFilm || action.buttonClicked.searchFilm || action.buttonClicked.removeFilm || action.buttonClicked.getAllFilms || action.buttonClicked.addActor || action.buttonClicked.modifyActor || action.buttonClicked.searchActor || action.buttonClicked.removeActor || action.buttonClicked.getAllActors">Remove Film</a>
<a href="ViewAllFilms.html" class="viewallfilms_buttton button1" ng-click="action.getAllFilms()" ng-hide="action.buttonClicked.addFilm || action.buttonClicked.modifyFilm || action.buttonClicked.searchFilm || action.buttonClicked.removeFilm || action.buttonClicked.getAllFilms || action.buttonClicked.addActor || action.buttonClicked.modifyActor || action.buttonClicked.searchActor || action.buttonClicked.removeActor || action.buttonClicked.getAllActors">View All Films</a>
<a href="#/AddNewActor" class="addactor_buttton button1" ng-click="action.addActor()" ng-hide="action.buttonClicked.addFilm || action.buttonClicked.modifyFilm || action.buttonClicked.searchFilm || action.buttonClicked.removeFilm || action.buttonClicked.getAllFilms || action.buttonClicked.addActor || action.buttonClicked.modifyActor || action.buttonClicked.searchActor || action.buttonClicked.removeActor || action.buttonClicked.getAllActors">Add Actor</a>
<a href="#/ModifyActor" class="modifyactor_buttton button1" ng-click="action.modifyActor()" ng-hide="action.buttonClicked.addFilm || action.buttonClicked.modifyFilm || action.buttonClicked.searchFilm || action.buttonClicked.removeFilm || action.buttonClicked.getAllFilms || action.buttonClicked.addActor || action.buttonClicked.modifyActor || action.buttonClicked.searchActor || action.buttonClicked.removeActor || action.buttonClicked.getAllActors">Modify Actor</a>
<a href="#/SearchActor" class="searchactor_buttton button1" ng-click="action.searchActor()" ng-hide="action.buttonClicked.addFilm || action.buttonClicked.modifyFilm || action.buttonClicked.searchFilm || action.buttonClicked.removeFilm || action.buttonClicked.getAllFilms || action.buttonClicked.addActor || action.buttonClicked.modifyActor || action.buttonClicked.searchActor || action.buttonClicked.removeActor || action.buttonClicked.getAllActors">Search Actor</a>
<a href="#/RemoveActor" class="removeactor_buttton button1" ng-click="action.removeActor()" ng-hide="action.buttonClicked.addFilm || action.buttonClicked.modifyFilm || action.buttonClicked.searchFilm || action.buttonClicked.removeFilm || action.buttonClicked.getAllFilms || action.buttonClicked.addActor || action.buttonClicked.modifyActor || action.buttonClicked.searchActor || action.buttonClicked.removeActor || action.buttonClicked.getAllActors">Remove Actor</a>
<a href="ViewAllActors.html" class="viewallactors_buttton button1" onclick="return submitMyForm();" ng-click="action.getAllActors()" ng-hide="action.buttonClicked.addFilm || action.buttonClicked.modifyFilm || action.buttonClicked.searchFilm || action.buttonClicked.removeFilm || action.buttonClicked.getAllFilms || action.buttonClicked.addActor || action.buttonClicked.modifyActor || action.buttonClicked.searchActor || action.buttonClicked.removeActor || action.buttonClicked.getAllActors">View All Actors</a>
<a href="#/" class="show_buttton button1" ng-click="showButtons()" ng-show="action.buttonClicked.addFilm || action.buttonClicked.modifyFilm || action.buttonClicked.searchFilm || action.buttonClicked.removeFilm || action.buttonClicked.getAllFilms || action.buttonClicked.addActor || action.buttonClicked.modifyActor || action.buttonClicked.searchActor || action.buttonClicked.removeActor || action.buttonClicked.getAllActors">Home</a>
<div ng-view></div>
</div>
</body>
</html>
我的AddNewActor.html是
<div id="login">
<h2><span class="fontawesome"></span>Add New Actor</h2>
<form action="AddNewActor" method="post">
<fieldset>
<p><label for="firstName">Enter Actor First Name</label></p>
<p><input type="text" name="firstName" value="first name" onBlur="if(this.value=='')this.value='first name'" onFocus="if(this.value=='first name')this.value=''"></p> <!-- JS because of IE support; better: placeholder="mail@address.com" -->
<p><label for="secondName">Enter Actor last Name</label></p>
<p><input type="text" name="lastName" value="last name" onBlur="if(this.value=='')this.value='last name'" onFocus="if(this.value=='last name')this.value=''"></p> <!-- JS because of IE support; better: placeholder="password" -->
<p><input type="submit" value="Submit"></p>
</fieldset>
</form>
</div>
我的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" 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>Film Management System</display-name>
<servlet>
<display-name>ViewAllActors</display-name>
<servlet-name>ViewAllActors</servlet-name>
<servlet-class>com.flp.fms.controller.ViewAllActors</servlet-class>
</servlet>
<servlet>
<description>
</description>
<display-name>ViewALLFilms</display-name>
<servlet-name>ViewALLFilms</servlet-name>
<servlet-class>com.flp.fms.controller.ViewALLFilms</servlet-class>
</servlet>
<servlet>
<description>
</description>
<display-name>AddNewActor</display-name>
<servlet-name>AddNewActor</servlet-name>
<servlet-class>com.flp.fms.controller.AddNewActor</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ViewAllActors</servlet-name>
<url-pattern>/ViewAllActors</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ViewALLFilms</servlet-name>
<url-pattern>/ViewALLFilms</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddNewActor</servlet-name>
<url-pattern>/AddNewActor</url-pattern>
</servlet-mapping>
</web-app>
我的AddNewActor.java(servlet)
package com.flp.fms.controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AddNewActor extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out=response.getWriter();
out.println("tdctdt");
}
}
答案 0 :(得分:1)
这可能是因为servlet路径错误。 因为在你的web.xml中,有一个映射
<servlet-mapping>
<servlet-name>AddNewActor</servlet-name>
<url-pattern>/AddNewActor</url-pattern>
</servlet-mapping>
当您致电AddNewActor
而非angularjs_webapp/AddNewActor
angularjs_webapp/htmlTemplates/AddNewActor
您可以通过在表单操作AddNewActor.html
中进行更改来修复它,以将调用定向到其父目录:
<form action="AddNewActor" method="post">
应改为
<form action="../AddNewActor" method="post">