这是我的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,不工作 –