警告: No configuration found for the specified action: '/sum.action' in namespac
e: ''. Form action defaulting to 'action' attribute's literal value.
拜谢各位大神,刚学struts2,不懂
e: ''. Form action defaulting to 'action' attribute's literal value.
拜谢各位大神,刚学struts2,不懂
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2" namespace="/" extends="struts-default">
<action name="sum" class="action.FirstAction" method="execute">
<result name="positive">/positive.jsp</result>
<result name="negative">/negative.jsp</result>
</action></package>
</struts>
<web-app 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">
<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>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>把 <url-pattern>/*</url-pattern>
改为/*.action
private int x;
private int y;
public int getX() {
return x;
}
public void setX(int x) {
System.out.println(x);
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
System.out.println(y);
this.y = y;
}
public String exeute()throws Exception
{
if(getSum()>=0)
{
return "positive";
}
else
{
return "negative";
}
}
public int getSum()
{
return x+y;
}}
: ''. Form action defaulting to 'action' attribute's literal value.
<%@ taglib uri="/struts-tags" prefix="s" %><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'sum.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<s:form action="sum.action" method="post">
<s:textfield name="x" lable="number1"/><br>
<s:textfield name="y" lable="number2"/><br>
<s:submit value="代数和"></s:submit>
</s:form>
</body>
</html>
大哥,我没写namespace
<s:form action="/sum.action" method="post">试试呢
两边都加了namespace还报这个错吗?
e: '/'. Form action defaulting to 'action' attribute's literal value.
<s:form name="ThisForm" action="reg"
method="post">
<table width="410" height="198" border="0" align="right"
cellpadding="0" cellspacing="0">
<tr>
<td><s:textfield name="username" label="用户名"
labelposition="center"></s:textfield></td>
</tr>
<tr>
<td><s:password name="password" label="密码"
labelposition="center"></s:password></td>
</tr>
<tr>
<td>
<s:password name="password1" label="再次输入密码"></s:password>
</td>
</tr>
<tr>
<td>
<s:radio list="#{'0':'男','1':'女'}" name="sex" label="性别"></s:radio>
</td>
</tr>
<tr>
<td>
<s:textfield label="email" name="email" ></s:textfield>
</td>
</tr>
<tr>
<td>
<s:textfield label="address" name="address" ></s:textfield>
</td>
</tr>
<tr>
<td height="10" colspan="2" valign="bottom"></td>
</tr>
<tr>
<td colspan="2" valign="top">
<input type="submit" value="提交" align="left">
<input type="button" onclick="doBack()" value="返回">
</td>
</tr>
<s:actionerror />
</table>
</s:form>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="struts2" extends="struts-default">
<action name="reg" class="com.action.LoginAction" method="reg">
<result name="success" type="redirect">main.jsp</result>
<result name="input">reg.jsp</result>
<result name="error">reg.jsp</result>
</action>
</package>
</struts>Action的:package com.action;import java.util.ArrayList;
import java.util.List;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;import org.apache.struts2.ServletActionContext;
import com.dao.UserDao;
import com.domain.User;
import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport { /**
*
*/
private static final long serialVersionUID = -2956743498330350292L;
public String username;
public String password;
public String password1;
public String getPassword1() {
return password1;
} public void setPassword1(String password1) {
this.password1 = password1;
} public String sex;
public String email;
public String address;
public String getAddress() {
return address;
} public void setAddress(String address) {
this.address = address;
} public String getSex() {
return sex;
} public void setSex(String sex) {
this.sex = sex;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
} private UserDao userDao; 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 UserDao getUserDao() {
return userDao;
} public void setUserDao(UserDao userDao) {
this.userDao = userDao;
} public void validate() {
if (username == null || username.length() == 0) {
super.addActionError("用户名不能为空");
}
if (password == null || password.length() == 0) {
super.addActionError("密码不能为空");
}
}
public String reg(){
User data=new User();
data.setUserName(username);
data.setUserPw(password);
data.setUserSex(sex);
data.setUserEmail(email);
data.setUserAddress(address);
if(!password.equals(password1)){
super.addActionError("两次输入的密码不同,请重新输入");
return ERROR;
}
try{
userDao.merge(data);
}catch(Exception e){
e.printStackTrace();
}
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session=request.getSession();
// User admin=l.get(0);
session.setAttribute("userType", 0);
session.setAttribute("admin", data);
return SUCCESS;
}
}
改为:
<s:form action="sum" method="post">
<s:textfield name="x" lable="number1"/><br>
<s:textfield name="y" lable="number2"/><br>
<s:submit value="代数和"></s:submit>
</s:form>