window环境编写jsp,上传到网站(linux服务器),访问servlet出404错误!
在window系统测试没有错误, 上传后访问html,jsp都没有问题,但是一旦有表单跳转到servlet,马上就报404错误!
这是managerLogin.jsp页面的内容:
- HTML code
<%@ 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>
这是web.xml的部分配置代码:
- XML code
<?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>
这是目录结构:
managerLogin.jsp 和 WEB-INF在同级目录下, Ser_ManagerLogin.java在colorjungle(项目名)/src/login/目录下,
项目编译后,在WEB-INF/classes/login目录下存在Ser_ManagerLogin.class文件!
这个问题困扰好长时间了! 由于是国外服务器,沟通不便! 对方一直说是我的code有问题! 我本地测试又没有问题, 望各位大大指点!
[解决办法]
友情up 没遇到过
[解决办法]
web容器换了吗?比如从resin到tomcat 或者weblogic 等等?我以前遇到换了web容器发生这样的
错误,然后改下容器的设置 或者有时候jdk版本不一致也会有404错误
[解决办法]
两种系统下的路径好像有点区别。
把
- Java code
<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系列有很大的。
[解决办法]
[解决办法]
linux和windows的路径是不一样的
[解决办法]
windows开发linux发布要用<%=request.getContextPath()%>取webroot
[解决办法]
web.xml的配置
[解决办法]
应该是你工程名的访问权限问题,那个目录没有访问权限。
要在服务器设置一下目录权限就可以了。
[解决办法]
404肯定是路径有问题 是我的话就一个个试试 servlet也常遇到路径问题 相对路径绝对路径问题
[解决办法]
估计是路径的问题
[解决办法]
check it
[解决办法]
现在linux上调试个简单的页面试试,看看行不行
[解决办法]
先看看web服务器有没有问题...
看web.xml...配置
<welcome-file-list>
<welcome-file>logon.jsp</welcome-file>
</welcome-file-list>
看能不能进入logon.jsp...
如果可以的话那就是配置servlet的错误了
<servlet-mapping>
<servlet-name>Ser_test</servlet-name>
<url-pattern> *.test</url-pattern>
</servlet-mapping>
<form id="form1" name="form1" method="post" action="Ser_test.test">
试试...
[解决办法]
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以上的