这是我的代码部分,感觉没有错误,我是初学者,请大家帮帮忙
我用的是NetBeans7.0login.html
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>提交表单数据</title>
</head>
<body bgcolor="#FFFFFF">
<h1 align="center"> <b>欢迎登录系统</b></h1>
<form action="getpostdata" method ="post"> <p> </p>
<table width="52%" border="2" align="center">
<tr bgcolor="#FFFFCC">
<td align="center" width="43%"> <div align="center">用户名:</div></td>
<td width="57%"> <div align="left">
<input type="text" name="username">
</div></td>
</tr>
<tr bgcolor="#CCFF99">
<td align="center" width="43%"> <div align="center">密 码:</div></td>
<td width="57%"> <div align="left">
<input type="password" name="password">
</div></td>
</tr>
</table>
<p align="center">
<input type="reset" name="Reset" value="重置">
<input type="submit" name="Submit2" value="提交">
</p>
</form>
</body>
</html> GetPostData.java
/*
* Created on 2004-6-13
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package com.servlet;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 GetPostData extends HttpServlet {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//TODO Method stub generated by Lomboz
//为解决编码问题后来添加
//response.setContentType("text/html;charset=gb2312");
//request.setCharacterEncoding("gb2312");//解决编码问题 PrintWriter out = response.getWriter();
out.println( //a tools method to show the html code with title
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + "get post data " + "</H1>\n" +
"<UL>\n" +
" <LI><B>username</B>: "
+ request.getParameter("username") + "\n" +
" <LI><B>password</B>: "
+ request.getParameter("password") + "\n" +
"</UL>\n" +
"</BODY></HTML>"); }
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
} /**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
} /**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<servlet>
<servlet-name>First</servlet-name>
<servlet-class>com.Servlet.First</servlet-class>
</servlet>
<servlet>
<servlet-name>GetPostData</servlet-name>
<servlet-class>com.Servlet.GetPostData</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>First</servlet-name>
<url-pattern>/First</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>GetPostData</servlet-name>
<url-pattern>/GetPostData</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这是错误信息
HTTP Status 404 - --------------------------------------------------------------------------------
type Status reportmessagedescriptionThe requested resource () is not available.--------------------------------------------------------------------------------
我用的是NetBeans7.0login.html
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>提交表单数据</title>
</head>
<body bgcolor="#FFFFFF">
<h1 align="center"> <b>欢迎登录系统</b></h1>
<form action="getpostdata" method ="post"> <p> </p>
<table width="52%" border="2" align="center">
<tr bgcolor="#FFFFCC">
<td align="center" width="43%"> <div align="center">用户名:</div></td>
<td width="57%"> <div align="left">
<input type="text" name="username">
</div></td>
</tr>
<tr bgcolor="#CCFF99">
<td align="center" width="43%"> <div align="center">密 码:</div></td>
<td width="57%"> <div align="left">
<input type="password" name="password">
</div></td>
</tr>
</table>
<p align="center">
<input type="reset" name="Reset" value="重置">
<input type="submit" name="Submit2" value="提交">
</p>
</form>
</body>
</html> GetPostData.java
/*
* Created on 2004-6-13
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package com.servlet;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 GetPostData extends HttpServlet {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//TODO Method stub generated by Lomboz
//为解决编码问题后来添加
//response.setContentType("text/html;charset=gb2312");
//request.setCharacterEncoding("gb2312");//解决编码问题 PrintWriter out = response.getWriter();
out.println( //a tools method to show the html code with title
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + "get post data " + "</H1>\n" +
"<UL>\n" +
" <LI><B>username</B>: "
+ request.getParameter("username") + "\n" +
" <LI><B>password</B>: "
+ request.getParameter("password") + "\n" +
"</UL>\n" +
"</BODY></HTML>"); }
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
} /**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
} /**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<servlet>
<servlet-name>First</servlet-name>
<servlet-class>com.Servlet.First</servlet-class>
</servlet>
<servlet>
<servlet-name>GetPostData</servlet-name>
<servlet-class>com.Servlet.GetPostData</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>First</servlet-name>
<url-pattern>/First</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>GetPostData</servlet-name>
<url-pattern>/GetPostData</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这是错误信息
HTTP Status 404 - --------------------------------------------------------------------------------
type Status reportmessagedescriptionThe requested resource () is not available.--------------------------------------------------------------------------------
<form action="GetPostData" method ="post">
但是出现新的错误HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessagedescriptionThe server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: PWC1381: Error allocating a servlet instance
root cause java.lang.NoClassDefFoundError: com/Servlet/GetPostData (wrong name: com/servlet/GetPostData)
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1 logs.
--------------------------------------------------------------------------------GlassFish Server Open Source Edition 3.1那个action框里的就是我写的java名吗?但是改了还不对啊
但是这里的路径是:com/servlet/GetPostData
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");//解决编码问题
PrintWriter out = response.getWriter();
out.println( //a tools method to show the html code with title
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + "get post data " + "</H1>\n" +
"<UL>\n" +
" <LI><B>username</B>: "
+ request.getParameter("username") + "\n" +
" <LI><B>password</B>: "
+ request.getParameter("password") + "\n" +
"</UL>\n" +
"</BODY></HTML>");
} @Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doGet(request, response);
不一致,改成一致就可以了。
<servlet-name>GetPostData</servlet-name>
<url-pattern>/GetPostData</url-pattern>
</servlet-mapping>
<form action="getpostdata" method ="post">
大小写不一致
改:<form action="GetPostData" method ="post">