這是我的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也試過,沒有結果 我看不懂,有什麼幫助嗎?
'StrutsPrepareAndExecuteFilter'更好,爲什麼不升級到最新版本? –
你可以試試這個網址:serveraddress/yourapname/insert.do或serveraddress/yourapname/insert.action –
我試過這個serveraddress/projectname/insert,不工作 –