struts:JSP获取服务器传过来的数据
本人小菜,想请教一个问题,我在action中有一个username字段,并在execute中设置了值,也设置了相应的get/set方法,百度谷歌了很多,都说在JSP页面中直接使用<s:property value="username"/>就可以取得值了,或者是Servlet的API把值放在作用域中就可以取得值了。
但是我这两种方式都试过了,都不行,取不出来。EL表达式也不好使。
代码:
package com.ccniit.action;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Override
public String execute() throws Exception {
username = "zhangsan";
return SUCCESS;
}
}
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="up" class="com.ccniit.action.TestAction">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="up" method="post">
<s:property value="username"/>
</form>
</body>
</html>