请大神指教为什么我的maven整合struts2可以直接跳转到jsp页面,但不能表单提交执行action跳转会报404。

qq_40332177 2017-12-13 01:37:25
请大神指教为什么我的maven整合struts2可以直接跳转到jsp页面,但不能表单提交执行action跳转会报404。

maven项目结勾如下:


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.devMode" value="true"></constant>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<constant name="struts.locale" value="zh_CN"></constant>

<package name="maven" namespace="/" extends="struts-default">
<action name="findById" class="com.hc.maven.action.LoginAction">
<result>
index.jsp
</result>
</action>
</package>
</struts>

LoginAction类:
package com.hc.maven.action;

import java.io.IOException;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
public String Name;
public int Age;

public String getResult() {
return Result;
}

public void setResult(String result) {
Result = result;
}

public String Result;

public String getName() {
return Name;
}

public void setName(String name) {
Name = name;
}

public int getAge() {
return Age;
}

public void setAge(int age) {
Age = age;
}

@Override
public String execute() throws Exception {
this.setResult("name:" + Name);
this.setResult(this.getResult() + "&age:" + String.valueOf(Age));
return "success";
}

}

web。xml:
<?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"
xmlns:web="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_2_5.xsd"
id="WebApp_ID" version="2.5">

<web:filter>
<web:filter-name>struts2</web:filter-name>
<web:filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</web:filter-class>
</web:filter>
<web:filter-mapping>
<web:filter-name>struts2</web:filter-name>
<web:url-pattern>/*</web:url-pattern>
</web:filter-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>info.jsp</welcome-file>
</welcome-file-list>

</web-app>

index.jsp文件:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="findById.action" method="post">
姓名<input type='text' name="Name"> <br />
年龄<input type='text' name=Age>
<input type="submit" value="提交">
</form>
</body>
</html>

pom.xml文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.hc</groupId>
<artifactId>parent</artifactId>
<version>0.0.3-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>

<artifactId>maven_frist</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>



<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.24</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
...全文
232 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_40332177 2017-12-18
  • 打赏
  • 举报
回复
不对,没有用啊。
vswen5 2017-12-13
  • 打赏
  • 举报
回复
struts2配置没写完整 应该是这样的 <action name="findById" class="com.hc.maven.action.LoginAction" method="execute"> <result name="success"> index.jsp </result>

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧