
因为一个老项目也遇到这个问题,所以希望回答能帮助到其他人。
在webxml里添加jsp servlet的js映射,在项目里或都tomat里添加都可以,就可以使用jsp应有的东西,同理,html也可以。需要使用到的标签库引用进去就可以。
JS可以如下:开头位置引入相关东西,最好contentType设置为js类型。
webxml
<servlet-mapping><servlet-name>jsp</servlet-name>
<url-pattern>jsp</url-pattern>
<url-pattern>jspx</url-pattern>
<url-pattern>/路径/js</url-pattern><!-- 不指定具体文件或路径为全部 -->
<url-pattern>html</url-pattern>
</servlet-mapping>
js里 就没有标签,谢谢
strus2 是在 服务器端解析的,将jsp中所有的标签解析后,传给浏览器,浏览器只解析 html 标签,其中一个标签 是 script 里面可以写 js语言,当浏览器拿到页面时 就已经没有一切 strus spring 等等的 标签了
所以js处理的标签 都是 html 标签,在 js里叫 dom
我草。。。首先本地不存在struts 标签。都是原始的html
js是客户端的。。struts是服务器端的。。
如果要用户通过js 拿到你的 userid
实现你所谓的传递。。自己写两份吧 反正不会显示。
<s:a href="javascript:getValue( ${userid } )">
里将这个参数
<s:property value="userId" />
传递给function javascript:getValue(jobId){
alert(jobId);
}
var str = "${sessionScopeaa}";
alert(str);
为何不行?
将action里面put的code和JS附近代码全部放出来
是可以实现的,具体如下:
值栈中存放着一些OGNL可以访问的数据,如下:
a:action的实例,这样就可以通过OGNL来访问Action实例中的属性的值了。
b:OGNL表达式运算的值,可以设置到值栈中,可主动访问值栈对象,强行设置。
c:OGNL表达式产生的中间变量,比如使用Struts2标签的时候,使用循环标签,自然会有循环的变量,这些都放在值栈中。
例子,修改用户输入的参数信息,如下图所示,
图:用户输入了aa的username
图:用户提交后发现username属性的值发生了变化
实现:
首先定义一个实现PreResultListener接口的类:MyPreResultListener
import comopensymphonyxwork2ActionInvocation;
import comopensymphonyxwork2interceptorPreResultListener;
public class MyPreResultListener implements PreResultListener {
@Override
public void beforeResult(ActionInvocation invocation, String resultCode) {
Systemoutprintln("现在处理Result执行前的功能, result=" + resultCode);
//在Result处理之前修改value stack里面的username对应的值
invocationgetInvocationContext()getValueStack()setValue("username", "被修改了");
}
}
然后在相应的Action中进行注册:
import comcapinfotechlistenerMyPreResultListener;
import comopensymphonyxwork2ActionContext;
import comopensymphonyxwork2ActionSupport;
public class PreResultAction extends ActionSupport {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
thisusername = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
thispassword = password;
}
public String execute() {
Systemoutprintln("用户输入的参数为,username:" + username + ", password:" + password);
ActionContext context = ActionContextgetContext();
MyPreResultListener preListener = new MyPreResultListener();
contextgetActionInvocation()addPreResultListener(preListener);
return "success";
}
}
以上就是关于js标签中使用Struts2中的s标签,像如下图使用是对的吗全部的内容,包括:js标签中使用Struts2中的s标签,像如下图使用是对的吗、js里yongstruts2的标签吗、struts标签向js传递参数等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)