我使用do post方法作为我的方法。我正在尝试在Tomcat 6.0.37上部署servlet。 Tomcat也起来了。我已将项目放在webapps文件夹中。当我打开localhost URL时,我得到了Tomcat的主页。当我填写欢迎JSP表单并点击提交按钮时,我收到以下错误:
请求的资源(/Airlines/ChooseAirline.do)不可用。
我搜索但找不到任何可以帮助我的东西。我在点击JSP上的提交按钮后尝试简单地获取消息,并检查它是否与Servlet有关。
我的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>Airlines</display-name>
<welcome-file-list>
<welcome-file>ChooseAirline.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>ChooseAirline</servlet-name>
<servlet-class>com.chooseairline.ChooseAirlines</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ChooseAirline</servlet-name>
<url-pattern>/ChooseAirline.do</url-pattern>
</servlet-mapping>
</web-app>
在我的servlet中我只是尝试打印hello world作为网页上的输出。我的servlet代码如下 -
package com.chooseairline;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
public class ChooseAirlines extends HttpServlet{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException
{
String requestDropDown = request.getParameter("dropDownSelectClass");
System.out.println("the value here is "+requestDropDown);
response.setContentType("text/html");
PrintWriter out;
try {
out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我是Servlet开发和Apache服务器的新手。我尝试了很多次,但遇到了同样的问题。
我还包括我的JSP。请检查 -
<!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=utf-8" />
<title>Generated by Pure CSS Menu.com : Free CSS Drop Down Menu Generator</title>
<meta name="description" content="Online CSS Menu Maker. Create No-Javascript, 100% CSS Dropdown Menu in seconds! Horizontal css menu & Vertical css menu." />
</head>
<form id="airLineform" name="airLineform" action="ChooseAirline.do" method="POST">
<body bgcolor="#ffffff" background="AirlineImage.jpg" onload="disableFields()" >
<!-- Start PureCSSMenu.com STYLE -->
<style>
body {
padding-left: 17em;
padding-top: 1em;
background-repeat:no-repeat;
}
#pcm{display:none;}
fieldset {
background-color: #333333;
padding-left: 2em;
padding-right: 2em;
border-color:#cccccc #111111 #111111 #cccccc;
#color: #111111;
font:normal 12px Trebuchet MS, Tahoma;
color: #cccccc;
}
#dropDownSelectClass {
padding: 5px;
#color:#333333;
font:normal 12px Trebuchet MS, Tahoma;
background-color: #cccccc;
-webkit-appearance: none;
}
ul.pureCssMenu ul{display:none}
ul.pureCssMenu li:hover>ul{display:block}
ul.pureCssMenu ul{position: absolute;left:-1px;top:98%;}
ul.pureCssMenu ul ul{position: absolute;left:98%;top:-2px;}
ul.pureCssMenu,ul.pureCssMenu ul {
margin:0px;
list-style:none;
padding:0px 2px 2px 2px;
background-color:#333333;
background-repeat:repeat;
border-color:#cccccc #111111 #111111 #cccccc;
border-width:1px;
border-style:solid;
}
?
ul.pureCssMenu table {border-collapse:collapse}ul.pureCssMenu {
display:block;
zoom:1;
float: left;
}
ul.pureCssMenu ul{
# width:155.4px;
}
#ul.pureCssMenu li{
# display:block;
# margin:2px 0px 0px 2px;
# font-size:0px;
#}
#ul.pureCssMenu a:active, ul.pureCssMenu a:focus {
#outline-style:none;
#}
ul.pureCssMenu a, ul.pureCssMenu li.dis a:hover, ul.pureCssMenu li.sep a:hover {
display:block;
vertical-align:middle;
background-color:#333333;
border-width:1px;
border-color:#333333;
border-style:solid;
text-align:left;
text-decoration:none;
padding:10px 10px 10px 80px;
_padding-left:0;
font:normal 12px Trebuchet MS,Tahoma;
color: #cccccc;
text-decoration:none;
cursor:default;
}
#ul.pureCssMenu span{
# overflow:hidden;
#}
ul.pureCssMenu li {
float:left;
}
ul.pureCssMenu ul li {
float:none;
}
ul.pureCssMenu ul a {
text-align:left;
white-space:nowrap;
}
#ul.pureCssMenu li.sep{
# text-align:left;
# padding:0px;
# line-height:0;
# height:100%;
#}
#ul.pureCssMenu li.sep span{
# float:none; padding-right:0;
# width:3px;
# height:100%;
# display:inline-block;
# background-color:#cccccc #111111 #111111 #cccccc; background-image:none;}
#ul.pureCssMenu ul li.sep span{
# width:100%;
# height:3px;
#}
ul.pureCssMenu li:hover{
position:relative;
}
ul.pureCssMenu li:hover>a{
# background-color:#377D9F;
# border-color:#377D9F;
# border-style:solid;
# font:normal 12px Trebuchet MS, Tahoma;
# color: #FFFFFF;
# text-decoration:none;
}
ul.pureCssMenu li a:hover{
position:relative;
background-color:#377D9F;
border-color:#377D9F;
border-style:solid;
font:normal 12px Trebuchet MS, Tahoma;
color: #FFFFFF;
text-decoration:none;
}
ul.pureCssMenu li.dis a {
# color: #666 !important;
}
#ul.pureCssMenu img {
#border: none;float:left;_float:none;margin-right:2px;width:16px;
#height:16px;
#}
ul.pureCssMenu ul img {
width:16px;
height:16px;
}
#ul.pureCssMenu img.over{display:none}
#ul.pureCssMenu li.dis a:hover img.over{display:none !important}
#ul.pureCssMenu li.dis a:hover img.def {display:inline !important}
#ul.pureCssMenu li:hover > a img.def {display:none}
#ul.pureCssMenu li:hover > a img.over {display:inline}
#ul.pureCssMenu a:hover img.over,ul.pureCssMenu a:hover ul img.def,ul.pureCssMenu a:hover a:hover ul img.def,ul.pureCssMenu a:hover a:hover a:hover ul #img.def,ul.pureCssMenu a:hover a:hover img.over,ul.pureCssMenu a:hover a:hover a:hover img.over,ul.pureCssMenu a:hover a:hover a:hover a:hover #img.over{display:inline}
#ul.pureCssMenu a:hover img.def,ul.pureCssMenu a:hover ul img.over,ul.pureCssMenu a:hover a:hover ul img.over,ul.pureCssMenu a:hover a:hover a:hover ul #img.over,ul.pureCssMenu a:hover a:hover img.def,ul.pureCssMenu a:hover a:hover a:hover img.def,ul.pureCssMenu a:hover a:hover a:hover a:hover img.def{display:none}
#ul.pureCssMenu a:hover ul,ul.pureCssMenu a:hover a:hover ul,ul.pureCssMenu a:hover a:hover a:hover ul{display:block}
#ul.pureCssMenu a:hover ul ul,ul.pureCssMenu a:hover a:hover ul ul{display:none}
ul.pureCssMenu span{
display:block;
background-image:url(./images/arr_white.gif);
background-position:right center;
background-repeat: no-repeat;
padding-right:12px;}
ul.pureCssMenu li:hover>a>span{ background-image:url(./images/arrv_white.gif);
}
ul.pureCssMenu a:hover span{ _background-image:url(./images/arrv_white.gif)}
ul.pureCssMenu ul span,ul.pureCssMenu a:hover table span{background-image:url(./images/arr_white.gif)}
</style>
<!-- End PureCSSMenu.com STYLE -->
<!-- Start PureCSSMenu.com MENU -->
<div text-align: center >
<table>
<tbody>
<tr>
<ul class="pureCssMenu pureCssMenum">
<li class="pureCssMenui" text-align: center><a class="pureCssMenui" href="#">About ChooseAirline</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">Aircrafts</a><!--[if lte IE 6]><table><tr><td><![endif]-->
<!--[if lte IE 6]></td></tr></table></a><![endif]--></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#"><span>Atrributes</span><![if gt IE 6]></a><![endif]><!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="pureCssMenum">
<li class="pureCssMenui"><a class="pureCssMenui" href="#">Value For Money</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">Seat Comfort</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">Staff Service</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">Catering</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">Entertainment</a></li>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]--></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">FAQ</a></li>
<li class="pureCssMenui"><a class="pureCssMenui" href="#">Contact Us</a></li>
</ul>
</tr>
<br />
<br />
<br />
<tr>
<td></td><td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
<td>
<fieldset>
   <p>
<label>Select the Class</label>  
 
<select id="dropDownSelectClass" name="dropDownSelectClass" onchange="enabalingFieldSet()">
<option value="defaulOption">Select a Class</option>
<option value="firstClass">First Class</option>
<option value="business">Business</option>
<option value="economy">Economy</option>
</select> <br> <br><br>
<div id="radioButtonsDiv" >
<label>Value for Money</label>
 <input type="radio" name="ValForMoney" value="good">Good<br>
                      
   <input type="radio" name="ValForMoney" value="medium">Medium
<br>
                      
   <input type="radio" name="ValForMoney" value="bad">Bad
<br>
<br>
<label>Set the preference for Value for Money</label>
     <input type="radio" name="prefValueForMoney" value="first">First
   <input type="radio" name="prefValueForMoney" value="second">Second
   <input type="radio" name="prefValueForMoney" value="third">Third
   <input type="radio" name="prefValueForMoney" value="fourth">Fourth
   <input type="radio" name="prefValueForMoney" value="five">Five
<br>
<br>
<br>
<label>Seat Comfort   </label>
  <input type="radio" name="seatComf" value="good">Good<br>
                      
   <input type="radio" name="seatComf" value="medium">Medium
<br>
                      
   <input type="radio" name="seatComf" value="bad">Bad
<br>
<br>
<label>Set the preference for Seat Comfort</label>
         <input type="radio" name="prefSeatComfort" value="first">First
   <input type="radio" name="prefSeatComfort" value="second">Second
   <input type="radio" name="prefSeatComfort" value="third">Third
   <input type="radio" name="prefSeatComfort" value="fourth">Fourth
   <input type="radio" name="prefSeatComfort" value="five">Five
<br>
<br>
<br>
<label>Staff Service</label>
     <input type="radio" name="staffService" value="good">Good<br>
                      
  <input type="radio" name="staffService" value="medium">Medium
<br>
                      
  <input type="radio" name="staffService" value="bad">Bad
<br>
<br>
<label>Set the preference for Staff Service</label>
         <input type="radio" name="prefStaffService" value="first">First
   <input type="radio" name="prefStaffService" value="second">Second
   <input type="radio" name="prefStaffService" value="third">Third
   <input type="radio" name="prefStaffService" value="fourth">Fourth
   <input type="radio" name="prefStaffService" value="five">Five
<br>
<br>
<br>
<label>Catering       </label>
    <input type="radio" name="catering" value="good">Good<br>
                      
  <input type="radio" name="catering" value="medium">Medium
<br>
                      
  <input type="radio" name="catering" value="bad">Bad
<br>
<br>
<label>Set the preference for Catering</label>
               <input type="radio" name="preCatering" value="first">First
   <input type="radio" name="preCatering" value="second">Second
   <input type="radio" name="preCatering" value="third">Third
   <input type="radio" name="preCatering" value="fourth">Fourth
   <input type="radio" name="preCatering" value="five">Five
<br>
<br>
<br>
<label>Entertainment</label>
  <input type="radio" name="entertainment" value="good">Good<br>
                      
  <input type="radio" name="entertainment" value="medium">Medium
                      
<br>
                         <input type="radio" name="entertainment" value="bad">Bad
<br>
<br>
<label>Set the preference for Entertainment</label>
      <input type="radio" name="prefEntertainment" value="first">First
   <input type="radio" name="prefEntertainment" value="second">Second
   <input type="radio" name="prefEntertainment" value="third">Third
   <input type="radio" name="prefEntertainment" value="fourth">Fourth
   <input type="radio" name="prefEntertainment" value="five">Five
<br>
<br>
<br>
</div>
                                                                 
<input type="submit" name="submit" value="Submit">
</p>
</td>
</fieldset>
</tr>
</tbody>
</table>
</div>
<!-- End PureCSSMenu.com MENU -->
<!-- (c) 2009, PureCSSMenu.com -->
<script>
function enabalingFieldSet(){
//alert('entered here');
//stylecolor= document.getElementById('dropDownSelectClass').selected;
//alert('entered here22 ');
var e = document.getElementById("dropDownSelectClass");
var strUser = e.options[e.selectedIndex].value;
if (strUser=='business' || strUser=='economy' || strUser=='firstClass'){
//alert('the selected value here is '+strUser);
enableFields();
}
else{
//alert('entered here222'+document.getElementById("radioButtonsDiv"));
document.getElementById("airLineform").reset();
disableFields();
}
// document.getElementById("foo").style.display="block";
// }else{
// document.getElementById("foo").style.display="none";
// }
// document.getElementById('dropDownSelectClass').style.color="black";
}
function disableFields()
{
var prefValueForMoneyradios = document.airLineform.prefValueForMoney;
var prefValLength=prefValueForMoneyradios.length;
for (var i=0; i<prefValLength; i++)
{
prefValueForMoneyradios[i].disabled = true;
}
var ValForMoneyradios = document.airLineform.ValForMoney;
//var prefValMoney=ValForMoneyradios.length;
for (var i=0; i<ValForMoneyradios.length; i++)
{
ValForMoneyradios[i].disabled = true;
}
var seatComfradios = document.airLineform.seatComf;
//var prefValLength=seatComfradios.length;
for (var i=0; i<seatComfradios.length; i++)
{
seatComfradios[i].disabled = true;
}
//
var prefSeatComfortradios = document.airLineform.prefSeatComfort;
//var prefValLength=prefSeatComfortradios.length;
for (var i=0; i<prefSeatComfortradios.length; i++)
{
prefSeatComfortradios[i].disabled = true;
}
//
var staffServiceradios = document.airLineform.staffService;
//var prefValLength=staffServiceradios.length;
for (var i=0; i<staffServiceradios.length; i++)
{
staffServiceradios[i].disabled = true;
}
//
var prefStaffServiceradios = document.airLineform.prefStaffService;
//var prefValLength=prefStaffServiceradios.length;
for (var i=0; i<prefStaffServiceradios.length; i++)
{
prefStaffServiceradios[i].disabled = true;
}
//
var cateringradios = document.airLineform.catering;
//var prefValLength=cateringradios.length;
for (var i=0; i<cateringradios.length; i++)
{
cateringradios[i].disabled = true;
}
//
var preCateringradios = document.airLineform.preCatering;
//var prefValLength=preCateringradios.length;
for (var i=0; i<preCateringradios.length; i++)
{
preCateringradios[i].disabled = true;
}
//
var entertainmentradios = document.airLineform.entertainment;
//var prefValLength=entertainment.length;
for (var i=0; i<entertainment.length; i++)
{
entertainment[i].disabled = true;
}
//
var prefEntertainmentradios = document.airLineform.prefEntertainment;
//var prefValLength=prefEntertainmentradios.length;
for (var i=0; i<prefEntertainmentradios.length; i++)
{
prefEntertainmentradios[i].disabled = true;
}
//
//
//document.airLineform.Date1.disabled=true
}
function enableFields()
{
var prefValueForMoneyradios = document.airLineform.prefValueForMoney;
var prefValLength=prefValueForMoneyradios.length;
for (var i=0; i<prefValLength; i++)
{
prefValueForMoneyradios[i].disabled = false;
}
var ValForMoneyradios = document.airLineform.ValForMoney;
//var prefValMoney=ValForMoneyradios.length;
for (var i=0; i<ValForMoneyradios.length; i++)
{
ValForMoneyradios[i].disabled = false;
}
var seatComfradios = document.airLineform.seatComf;
//var prefValLength=seatComfradios.length;
for (var i=0; i<seatComfradios.length; i++)
{
seatComfradios[i].disabled = false;
}
//
var prefSeatComfortradios = document.airLineform.prefSeatComfort;
//var prefValLength=prefSeatComfortradios.length;
for (var i=0; i<prefSeatComfortradios.length; i++)
{
prefSeatComfortradios[i].disabled = false;
}
//
var staffServiceradios = document.airLineform.staffService;
//var prefValLength=staffServiceradios.length;
for (var i=0; i<staffServiceradios.length; i++)
{
staffServiceradios[i].disabled = false;
}
//
var prefStaffServiceradios = document.airLineform.prefStaffService;
//var prefValLength=prefStaffServiceradios.length;
for (var i=0; i<prefStaffServiceradios.length; i++)
{
prefStaffServiceradios[i].disabled = false;
}
//
var cateringradios = document.airLineform.catering;
//var prefValLength=cateringradios.length;
for (var i=0; i<cateringradios.length; i++)
{
cateringradios[i].disabled = false;
}
//
var preCateringradios = document.airLineform.preCatering;
//var prefValLength=preCateringradios.length;
for (var i=0; i<preCateringradios.length; i++)
{
preCateringradios[i].disabled = false;
}
//
var entertainmentradios = document.airLineform.entertainment;
//var prefValLength=entertainment.length;
for (var i=0; i<entertainment.length; i++)
{
entertainment[i].disabled = false;
}
//
var prefEntertainmentradios = document.airLineform.prefEntertainment;
//var prefValLength=prefEntertainmentradios.length;
for (var i=0; i<prefEntertainmentradios.length; i++)
{
prefEntertainmentradios[i].disabled = false;
}
//
//
//document.airLineform.Date1.disabled=true*/
}
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
</script>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</body>
</form>
</html>
答案 0 :(得分:-1)
尝试以下内容。
action="/ChooseAirline.do"
如果不起作用
试
action="../ChooseAirline.do"