开发工具:myEclipe+tomcat6.0.
目录:d:\tomcat6\webapps\SystemBBS\
下面有文件src,包com.bbs.action 类LoginAction.java
还有文件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/dt ds/struts-2.0.dtd"> <struts>
<package name="struts2" extends="struts-default">
<action name="login" class="com.bbs.action.LoginAction">
<result name="success">/success.jsp </result>
<result name="failure">/failure.jsp </result>
</action>
</package>
</struts>
d:\tomcat6\webapps\SystemBBS\rootbbs下面存放web页面,
login.jsp内容
<body>
<form action="login.action" method="post">
username: <input type="text" name="username"/> <br>
password: <input type="text" name="password"/> <br>
<input type="submit" value="submit"/>
</body> 其下的WEB-INF:web.xml 内容
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_5.xsd">
<display-name>Struts Blank </display-name>
<!--定义Struts2的FilterDispatcher的Filter-->
<filter>
<!--定义核心Filter的名字-->
<filter-name>struts2 </filter-name>
<!--定义核心Filter的实现类-->
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
</filter>
<!--FilterDispatcher用来初始化Struts2并且处理所有的Web请求-->
<filter-mapping>
<filter-name>struts2 </filter-name>
<url-pattern>/* </url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.jsp </welcome-file>
</welcome-file-list>
</web-app> struts的jar文件已经导入在lib目录下,但是运行login.jsp
总是提示:HTTP Status 404 - /SystemBBS/rootbbs/login.action我的web.xml和struts.xml都配置了,怎么还是这种错误。
目录:d:\tomcat6\webapps\SystemBBS\
下面有文件src,包com.bbs.action 类LoginAction.java
还有文件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/dt ds/struts-2.0.dtd"> <struts>
<package name="struts2" extends="struts-default">
<action name="login" class="com.bbs.action.LoginAction">
<result name="success">/success.jsp </result>
<result name="failure">/failure.jsp </result>
</action>
</package>
</struts>
d:\tomcat6\webapps\SystemBBS\rootbbs下面存放web页面,
login.jsp内容
<body>
<form action="login.action" method="post">
username: <input type="text" name="username"/> <br>
password: <input type="text" name="password"/> <br>
<input type="submit" value="submit"/>
</body> 其下的WEB-INF:web.xml 内容
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_5.xsd">
<display-name>Struts Blank </display-name>
<!--定义Struts2的FilterDispatcher的Filter-->
<filter>
<!--定义核心Filter的名字-->
<filter-name>struts2 </filter-name>
<!--定义核心Filter的实现类-->
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
</filter>
<!--FilterDispatcher用来初始化Struts2并且处理所有的Web请求-->
<filter-mapping>
<filter-name>struts2 </filter-name>
<url-pattern>/* </url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.jsp </welcome-file>
</welcome-file-list>
</web-app> struts的jar文件已经导入在lib目录下,但是运行login.jsp
总是提示:HTTP Status 404 - /SystemBBS/rootbbs/login.action我的web.xml和struts.xml都配置了,怎么还是这种错误。
我的web.xml里边是这样配置的
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param> <filter> <filter-name>struts-cleanup</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ActionContextCleanUp
</filter-class>
</filter> <filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>希望对你有帮助!
如果没用spring 那个applicationContext.xml 的配置可以去掉
这个访问的路径不对所以找不到,才会报出404错误
如果你这么访问,他会去你的struts2的/rootbbs命名空间下查找login.action
而你的struts2的配置文件里并没有设置/rootbbs这个命名空间
你可以将<package name="struts2" extends="struts-default">
改成<package name="struts2" namespace="/rootbbs" extends="struts-default">
试一下
<filter-name>struts2 </filter-name>
<url-pattern>/* </url-pattern>
</filter-mapping> 你都过滤了所有的url所以你用 login.jsp看不到页面 你可以改成<url-pattern>*.action</url-pattern>
改为
<form action="/SystemBBS/rootbbs/login.action" method="post">
试试
<welcome-file>index.jsp </welcome-file>
</welcome-file-list> 你把index.jsp改成login.jsp,保存重新启动就OK哦
HTTP Status 404 - /SystemBBS/rootbbs/login.action 提示是在rootbbs目录下找不到login.action
你把
<form action="login.action" method="post">
改成
<form action="/login.action" method="post">
试一试。
login.jsp
success.jsp
failure.jspLoginAction.java在SystemBBS/src目录下面 com.bbs.action上面大家说的办法都试过,还是那个错误提示!
HTTP Status 404 - /SystemBBS/login.action,可是我的action在rootbbs的web-inf下面的classess里面呀。
http://localhost:8080/struts_login/WebRoot/login.jsp,点击提交,还是同样的错误呀!HTTP Status 404 - /struts_login/WebRoot/login.do
http://localhost:8080/struts_login/WebRoot/login.jsp,点击提交,还是同样的错误呀! HTTP Status 404 - /struts_login/WebRoot/login.do
楼上正解
迷糊。。@@ 嘿嘿, 学习ing..
你给我的工程里面,你的index.jsp和login.jsp是在同一个目录下面的,所以不需要在前面加WebRoot/,还有就是你报的这个错误,很明显的说明找不到你的login.do,因为你的login.do应该在struts_login目录下而不是WebRoot目录,你可以在提交的是侯在login.do前面加个/
还有就是你给我的工程我也是用的Tomcat6.0我运行哦没有问题。
好好向你学习!