首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jsp与servlet之间参数传递出现有关问题。jsp提交后无响应··

2012-10-26 
jsp与servlet之间参数传递出现问题。jsp提交后无响应以下是index.jsp的内容%@ page languagejava impor

jsp与servlet之间参数传递出现问题。jsp提交后无响应··
以下是index.jsp的内容
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>张旭,servlet练习程序</title>
</head>
<body>
<table width="778" border="0"> 
<tr> 
<td>
<P>请你输入一个年份以查询是否为闰年!</P>
<form method="post">
<input type="text" name="text1">
<input type="submit" value="查询">
</form>
</td> 
</tr>
</table> 
</body>
</html>
——————————————————————————————————————————————————————
以下是Chuli.java的内容
package com;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
 * Servlet implementation class Chuli01
 */
@WebServlet("/Chuli01")
public class Chuli01 extends HttpServlet {
private static final long serialVersionUID = 1L;
   
  /**
  * @see HttpServlet#HttpServlet()
  */
  public Chuli01() {
  super();
  // TODO Auto-generated constructor stub
  }

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.doPost(request, response);
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


response.setContentType("text/html");
  PrintWriter out = response.getWriter();

  HttpSession session = request.getSession(true);
String number = request.getParameter("text1"); //在文本域中获得数值
int runnian = Integer.parseInt(number); //将树枝变成整数
if(1000<runnian&&runnian<9999){ //判断数值是否在一般范围内
if(runnian/100==0){ //判断该年份是否为世纪年
if(runnian/4==0){
response.sendRedirect("runnian.jsp");
}else{
response.sendRedirect("pingnian.jsp");
}
}else if(runnian/4==0){ //是否为平年
response.sendRedirect("runnian.jsp");
}else{
response.sendRedirect("pingnian.jsp");
}
}else{
response.sendRedirect("error.jsp");
}
}

}
——————————————————————————————————————————————————————
以下是我的web.xml内容

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements. See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software


  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0"
  metadata-complete="true">
<servlet>
  <description>
  Welcome to Tomcat
  </description>
  <servlet-name>Chuli01</servlet-name>
  <servlet-class>com.Chuli01</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Chuli01</servlet-name>
<url-pattern>/com/Chuli01</url-pattern>
</servlet-mapping>


</web-app>

——————————————————————————————————————————————————————
问题描述,能成功运行index.jsp。并且启动tomcat的时候没有报错。
但点击查询按钮之后,整个页面并不跳转,似乎是参数没有被提交给servlet执行~,请问是什么情况,是不是我的程序书写并不完整?希望各位大虾能够帮我看看···非常非常感谢···

[解决办法]
在index.jsp中的form一行改成如下:
<form action="Chuli01" method="post">
[解决办法]

探讨
在index.jsp中的form一行改成如下:
<form action="Chuli01" method="post">

[解决办法]
不用直接写包的路径,你在xml里面已经配置的有包的路径了,你把项目名写上,试试看ok不

热点排行