日期:2014-05-17  浏览次数:20812 次

求助。关于jsp调用action
1、jsp调用action 不用<form action="">这种方式。还有别的吗?想做个按钮onclick事件直接调用action中我想用的方法。比如返回,菜单的按钮。一般jsp网站如何设计按钮,跳转等?
2、<% 
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>这个获得了basePath,怎么放入标签里。

先谢谢各位。
jsp action

------解决方案--------------------
1.<button onclick=“jsfunciont(调用action)”.....>
2.value=<%=basePath %>
------解决方案--------------------
1.button.submit……
2.<%=basePath%>
------解决方案--------------------
1 jsp中访问action还是action中的方法?
   ./xxx.do?id=xx根据id的值调用不同的方法可以不?
2 用<%= %>不行么?
------解决方案--------------------
可以用ajax 啊,
button onclick=""; 调用javascript
------解决方案--------------------
1、用<%=%>
2、用隐藏表单
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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 'test.jsp' starting page</title>
    <script type="text/javascript">
function showValue() {
document.getElementById("path").value = document.getElementById("hidden").value;
}
</script>
  </head>
  <body>
   BathPath:<input id="path" type="text" value="<%=basePath %>">
   <input type = "hidden" name="hidden" value="<%=basePath%>">
   <input type="button" value="showValue" onclick="showValue()">
  </body>
</html>

------解决方案--------------------
如果有basePath ,那jsp默认路径前都自动加的。
你可以搞个onclick事件,用脚本做
function(){
    location.href="action";
}
------解决方案--------------------
action名_方法名
------解决方案--------------------
可以用jquery 使用ajax方式动态访问action
------解决方案--------------------
1.location.href="xxxx.do!save",不过现在不提倡这么访问xxxxAction中的save()方法了。
2.如果你用相对路径,那么默认是加在你写的路径前面的,<%=basePath%>可以得到
------解决方案--------------------
jsp:
<input type='button' class='submit' value='提交'/>
js:
$('document').ready(function() {
    $('.submit').click(function() {
       $.post('text.action',{},function(data){
       alert(data); 
})
});
});
------解决方案--------------------