window环境编写jsp,上传到网站(linux服务器),访问servlet出404错误!
在window系统测试没有错误, 上传后访问html,jsp都没有问题,但是一旦有表单跳转到servlet,马上就报404错误!
这是managerLogin.jsp页面的内容:
<%@ page contentType="text/html; charset=gbk" language="java"%><html><head><title>SEIE Website Manager</title><link href="style/se.css" type="text/css" rel="stylesheet"/><script language="javascript" type="text/javascript" src="style/se.js"></script></head><body><table width="100%" height="100%"><tr><td align="center" vlign="middle"><form id="managerform" name="managerform" method="post" action="Ser_ManagerLogin"><table width="400" height="300" border="0" cellpadding="0" cellspacing="0" style="border-left:1px solid; border-right:1px solid; border-bottom:1px solid; border-top:1px solid; border-color:#000000; vertical-align:middle; margin-left:auto;margin-right:auto;" valign="center"> <tr> <th colspan="2" scope="col"><img src="img/websiteManager.jpg" alt="website Manager" width="400" height="138" /></th> </tr> <tr> <td height="18" colspan="2" bgcolor="#666666"></td> </tr> <tr> <td height="18" colspan="2" bgcolor="#FFFFFF"></td> </tr> <tr> <td width="200" height="18" align="right" bgcolor="#FFFFFF">UserName: </td> <td align="left" bgcolor="#FFFFFF"><input type="text" name="username" id="username" onkeypress="javascript:mgrLoginOnKey(event);"/></td> </tr> <tr> <td height="18" colspan="2" bgcolor="#FFFFFF"></td> </tr> <tr> <td width="200" height="18" align="right" bgcolor="#FFFFFF">Password: </td> <td height="18" align="left" bgcolor="#FFFFFF"><input type="password" name="password" id="password" onkeypress="javascript:mgrLoginOnKey(event);"/></td> </tr> <tr> <td height="18" colspan="2" bgcolor="#FFFFFF"></td> </tr> <tr> <td height="18" colspan="2" align="center" bgcolor="#FFFFFF"> <a onFocus="if(this.blur)this.blur()" onClick="javascript:checkmanagerform();return false;" style="cursor:pointer;"> Login </a> <a href="index.jsp">Home</a> </td> </tr> <tr> <td height="18" colspan="2" bgcolor="#FFFFFF"></td> </tr> <tr> <td height="18" colspan="2" bgcolor="#FFFFFF"></td> </tr> </table> </form> </td> </tr> </table></body></html>
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <servlet-name>Ser_ManagerLogin</servlet-name> <servlet-class>login.Ser_ManagerLogin</servlet-class> </servlet> <servlet-mapping> <servlet-name>Ser_ManagerLogin</servlet-name> <url-pattern>/Ser_ManagerLogin</url-pattern> </servlet-mapping></web-app>
<form id="managerform" name="managerform" method="post" action="Ser_ManagerLogin">
[解决办法]
设置apache的mod_jk2,把/Ser_ManagerLogin的请求转到tomcat
[解决办法]
<url-pattern>/Ser_ManagerLogin</url-pattern>
<form id="managerform" name="managerform" method="post" action="/Ser_ManagerLogin">
我更趋向于这个,其实你可以手动测试一下,因为404肯定是找不到的异常,不是程序异常。
100%是你输入的url路径问题。
[解决办法]
不同的Jdk環境也可能導致你的java文件在linux上編譯出錯,同樣無法生成class文件,servlet當然找不到了,所以404
最好你在相同或相似的條件測試一下,windows系列與unix系列會有很大區別的。
[解决办法]
试试...
[解决办法]
package editAction;
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 Ser_test extends HttpServlet {
/**
* Constructor of the object.
*/
public Ser_test() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void service(HttpServletRequest req, HttpServletResponse resp){
doPost(req, resp);
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
super.doGet(req, resp);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// 获取上下文路径
String path = request.getContextPath();
String newname = (request.getParameter("newname") == null) ? "" :request.getParameter("newname");
out.write("name="+newname);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
试试
[解决办法]
你在windows下把项目打包成war文件,再传到linux下的tomcat去运行,可以这样试一下,
因为你在windows下做的项目跟linux下的有很多东西都不一样了,不如jdk,tomcat,环境变量,环境。。。。。。。 打包以后在linux下不会出现这种情况了,jdk的版本要1.4以上的