Reputation: 1
The action reg1
is not called when I click a submit button.
My simple Struts application is as follows:
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/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee z http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Struts2</display-name>
<welcome-file-list>
<welcome-file>index.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>
reg.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="reg1" >
Username: <input type="text" name="username"> Password: <input
type="text" name="password"> Mobile: <input type="text"
name="mobile"> <input type="submit" >
</form>
</body>
</html>
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="default" extends="struts-default" namespace="/">
<action name="reg1.action" class="bean.regbean">
<result name="success">/login.jsp</result>
</action>
</package>
</struts>
Upvotes: 0
Views: 513
Reputation: 1
The action is not invoked because it's incorrectly mapped to the url in the form action attribute. Use this action configuration to map the action name, which is used without .action
suffix.
<action name="reg1" class="bean.regbean">
<result name="success">/login.jsp</result>
</action>
Also note, that FilterDispatcher
is deprecated in the latest Struts2 release. So, you have to upgrade and modify web.xml accordingly. In the JSP you can use struts tags to bind fields to the bean properties.
Upvotes: 2