小小的问题,struts总跳到上一层目录

chaoliu1024 2014-01-20 12:33:01
做了一个小练习,发现struts总跳转到tomcat webapps目录,检查半天了,总是感觉没错,大家帮忙看看
web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></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.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>


struts中的配置
    <package name="default" namespace="/" extends="struts-default">
<action name="struts" class="org.action.StrutsAction">
<result name="success">/welcome.jsp</result>

</action>
</package>


StrutsAction.java文件
public class StrutsAction extends ActionSupport {

private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String execute() throws Exception {
if(!name.equals("Hell")){
Map request = (Map)ActionContext.getContext().get("request");
request.put("name", getName());
return SUCCESS;
}else{
return ERROR;
}
}
}


前台代码
  <body>
<form action="struts.action" method="post">
请输入姓名:<input type="text" name="name"/><br>
<input type="submit" value="提交"/>
</form>
</body>


点击提交按钮,跳转到http://localhost:8080/struts.action下,应该为http://localhost:8080/工程名/struts.action才对啊。。。
麻烦大家帮我看看为什么?
...全文
238 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chaoliu1024 2014-01-20
  • 打赏
  • 举报
回复
引用 1 楼 magi1201 的回复:
改为
<form action="/struts.action" method="post">
试试
还是不可以
姜小白- 2014-01-20
  • 打赏
  • 举报
回复
改为
<form action="/struts.action" method="post">
试试
sxax 2014-01-20
  • 打赏
  • 举报
回复

<s:form action="/struts.action" method="post">....</s:form>
sxax 2014-01-20
  • 打赏
  • 举报
回复
引用 4 楼 rui888 的回复:
action="${pageContext.request.contextPath}/struts.action"
在没使用struts2的标签的时候可以使用el来进行
姜小白- 2014-01-20
  • 打赏
  • 举报
回复
引用 2 楼 zhzxlc_06 的回复:
还是不可以
楼主问题解决了吗?我在eclipse上搭了个struts2工程,就用了你的代码,配置文件,跑起来没问题的。
tony4geek 2014-01-20
  • 打赏
  • 举报
回复
action="${pageContext.request.contextPath}/struts.action"
teemai 2014-01-20
  • 打赏
  • 举报
回复
<form action="工程名/struts.action" method="post">

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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