我用表单提交一个变量 然后用Servlet再返回值 但是总是在提交表单的时候出错 404错误部署Servlet应该都注意什么 为什么我总是错呢~ 而且又找不到错误!
工程名为test
我的代码是:
=============================================
srvlet_1.jsp文件:放在test项目根目录下
<%@ page contentType="text/html; charset=utf-8" language="java" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Servlet—1</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="/zhuce">
姓名:<input type="text" name="name" id="textfield" /> <input type="submit" name="button" id="button" value="提交" />
</form>
</body>
</html>
==========================================================================
servlet.java文件:放在test\WEB-INF\src\servlet下 编译成功后放在test\WEB-INF\classes\servlet下
package servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class servlet_11 extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html;charset=GB2312");
PrintWriter out=response.getWriter();
request.setCharacterEncoding("GB2312");
String name=request.getParameter("name");
out.print("<html><head><title>Servlet的简单应用!</title></head>\n");
out.print("<body><h2><center>");
out.print("姓名:"+name);
out.print("</center></h2><body></html>");
}
}
========================================
web.xml文件:
添加了
<servlet>
<servlet-name>cui</servlet-name>
<servlet-class>servlet.servlet_11</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cui</servlet-name>
<url-pattern>/zhuce</url-pattern>
</servlet-mapping>然后就是不能运行 出错 谁帮我找找错误呀~~
工程名为test
我的代码是:
=============================================
srvlet_1.jsp文件:放在test项目根目录下
<%@ page contentType="text/html; charset=utf-8" language="java" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Servlet—1</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="/zhuce">
姓名:<input type="text" name="name" id="textfield" /> <input type="submit" name="button" id="button" value="提交" />
</form>
</body>
</html>
==========================================================================
servlet.java文件:放在test\WEB-INF\src\servlet下 编译成功后放在test\WEB-INF\classes\servlet下
package servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class servlet_11 extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html;charset=GB2312");
PrintWriter out=response.getWriter();
request.setCharacterEncoding("GB2312");
String name=request.getParameter("name");
out.print("<html><head><title>Servlet的简单应用!</title></head>\n");
out.print("<body><h2><center>");
out.print("姓名:"+name);
out.print("</center></h2><body></html>");
}
}
========================================
web.xml文件:
添加了
<servlet>
<servlet-name>cui</servlet-name>
<servlet-class>servlet.servlet_11</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cui</servlet-name>
<url-pattern>/zhuce</url-pattern>
</servlet-mapping>然后就是不能运行 出错 谁帮我找找错误呀~~
解决方案 »
- (function(){//coding....})() 请问这是什么意思
- request.getCookies()获取不到以保存在硬盘中的cookie,求教~~~
- 高分求一个SSH2框架~~~~~~~~~~
- Spring中的cglib-nodep-2.1.3.jar与Hibernate中的cglib-2.2.jar相冲突!
- linux下配置jsp(ssh开发)问题
- 穷人跪求:如何在局域网发布刚做好的网页
- 遇到难题了 很急,高手们帮下忙!文件批量上传问题。
- IE会直接打开下载文件(文本文件等),请问如何让它显示“保存”对话框?注意:ftp服务器和web服务器不在同一机器上
- 给初学者一个ABC入门的建议
- tomcat重新部署后数据库连接池并没有关闭
- jsp中a连接没有手型了
- 一些jsp异常分析理解
在servlet里post加了吗?还是只加了doget
404这种错误需要注意地址栏的变化和大小写问题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Servlet—1 </title>
</head>
<body>
<form id="form1" name="form1" action="zhuce">
姓名: <input type="text" name="name" id="textfield" /> <input type="submit" name="button" id="button" value="提交" />
</form>
</body>
</html> 我这里改成这样的就可以了,你可以再试一下。
错误二:form里method是"post",serlvet里只有doGet方法没有doPost方法
个人认为action的地址错了action的地址应该是zhuce,
还有没有dopost方法
你看你的web.xml 里面,看是不是空格的问题
<form action="<%=basePath%>/zhuce" method="post">
</form> 绝对路径与相对路径的问题
可参考以前的讨论
http://topic.csdn.net/u/20091122/21/0809f147-23ec-4c7c-a563-1c0997ed5807.html
用post方法提交 那边用get方法得到参数返回 能读到才怪呢修改一个 改成一样的