2014-01-07 78 views
0

这是我的web.xml匹配错误404 - 没有找到,服务器没有找到任何请求URI

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"  
     version="3.0"> 
<display-name>struts2app</display-name> 
<welcome-file-list> 
<welcome-file>index.html</welcome-file> 
<welcome-file>index.htm</welcome-file> 
<welcome-file>index.jsp</welcome-file> 
<welcome-file>default.html</welcome-file> 
<welcome-file>default.htm</welcome-file> 
<welcome-file>default.jsp</welcome-file> 
</welcome-file-list> 

<filter> 
<filter-name>struts2</filter-name> 
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>struts2</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 
</web-app> 

这是我在struts.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
    "http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 


    <package name="struts2app" extends="struts-default" namespace="/"> 
     <action name="insert" class="info.trisan.Insert" method="execute"> 
      <result name="fail">/insert.jsp</result> 
      <result name="success">/success.jsp</result> 
     </action> 

    </package> 
</struts> 

这是我的jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html> 
<head></head> 
<body> 
<form action="insert"> 
<label>Serial no</label> 
<input type="text" name="sno"/><br/> 
<label>Ser Name</label> 
<input type="text" name="sname"/><br/> 
<label>Ser country</label> 
<input type="text" name="scountry"/><br/> 

<input type="submit" value="click me"/> 
</form> 
</body> 
</html> 

这是我的动作类

package info.trisan; 
import java.sql.*; 

public class Insert { 
String sno; 
String sname; 
String scountry; 

public String getSno() { 
    return sno; 
} 

public void setSno(String sno) { 
    this.sno = sno; 
} 

public String getSname() { 
    return sname; 
} 

public void setSname(String sname) { 
    this.sname = sname; 
} 


public String getScountry() { 
    return scountry; 
} 

public void setScountry(String scountry) { 
    this.scountry = scountry; 
} 

public String execute(){ 
     String output="fail"; 

     int sn=Integer.parseInt(sno); 
    try{ 
     Class.forName("com.mysql.jdbc.Driver"); 
     Connection con=DriverManager.getConnection("url", "abc", "abc"); 
     PreparedStatement pst=con.prepareStatement("insert into details values(?,?,?"); 
     int n=pst.executeUpdate(); 
     if(n==sn){ 
      output="success"; 
     }   
    } 
    catch(SQLException sqe){ 
     System.out.println(sqe.toString()); 
    } 
    catch(ClassNotFoundException sqe){ 
     System.out.println(sqe.toString()); 
      }  
     return output; 
} 

} 

这里IAM试图welogic12

servser地址/ struts2app与此代码运行/ 那么jsp页面被打开,一旦点击提交它显示以下错误

错误404 - 找不到 RFC 2068超文本传输​​协议 - HTTP/1.1: 10.4.5 404未找到

服务器未找到任何与请求URI相匹配的内容。没有迹象表明病情是暂时的还是永久性的。

如果服务器不希望将该信息提供给客户端,则可以使用状态码403(禁止)。如果服务器通过某种内部可配置机制知道旧资源永久不可用并且没有转发地址,则应使用410(Gone)状态码。

我试过用StrutsPrepareAndExecuteFilter也试过,没有结果 我看不懂,有什么帮助吗?

+0

'StrutsPrepareAndExecuteFilter'更好,为什么不升级到最新版本? –

+0

你可以试试这个网址:serveraddress/yourapname/insert.do或serveraddress/yourapname/insert.action –

+0

我试过这个serveraddress/projectname/insert,不工作 –

回答

1

最好的解决方案是 1)如果web.xml文件中有<transport-guarantee>标记,那么将其值从CONFIDENTIAL更改为NONE。如果第一个解决方案不起作用,那么假设你的项目的登录页面是 http://localhost:8080/ABC/login.jsp然后复制ABC并将其粘贴到application.xml文件的<context-root>标记中。 这个技术对我有用

相关问题