SSH框架在整合Struts2和spring有,项目运行控制台不报错,但页面出现404,这是什么情况啊
web.xml配置文件件的代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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">
<display-name>Struts Blank</display-name>
<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>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.xml配置文件的代码:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
>
<bean id="loginAction" class="demo.struts.LoginAction"></bean>
</beans>
struts.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.objectFactory" value="spring"/>
<include file="struts-default.xml"></include>
<package name="login" extends="struts-default">
<action name="login" class="loginAction">
<result>/success.jsp</result>
<result name="fail">/fail.jsp</result>
</action>
</package>
</struts>
action的代码:
package demo.struts;
import org.springframework.web.struts.ActionSupport;
public class LoginAction extends ActionSupport {
private String tip;
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getTip() {
return tip;
}
public void setTip(String tip) {
this.tip = tip;
}
public String execute(){
if(username.equals("admin")&& password.equals("1234")){
setTip("登录成功");
return "success";
}
else
{
setTip("登录失败!用户名或密码吗错误!");
return "fail";
}
}
}
struts spring 框架 ssh
[解决办法]
404 标准的没找到页面,没有请求到服务器,你服务器也没办法给出响应,所以不会报错的。
如果是500 那说明是程序报的错
[解决办法]
<result name="success">/success.jsp</result>
[解决办法]
在package上加namespace="/"试一下
[解决办法]
还有最好把你的请求地址贴出来,根据你的web.xml,如果请求地址是http://hostname:port/projectname/,那最后请求的应该是http://hostname:port/projectname/login.html,那应该是要修改struts扩展名