每次,都想着,下次不要再搞网站这些了!
但是每次都要搞,好烦。
好吧。那就记录下吧,免得每次重新查找。
1.超链接
<a href="show.do?turnPage=prev">
show.do,就是在struts-config.xml(见最后的例子)里定义好的,然后turnPage是自变量,赋予值prev,在action可以这么弄:
String str = request.getParameter("turnPage");
2.form
这种这么常见的,就不用说了吧。
<form name=form1 method=post enctype=multipart/form-data action=imageSearch.do>
</form>
3.javascript
两种吧。
一是,在form里有个type=submit的input,那么首先要判断下,再提交,通过javascript里的return true/false可以控制是否提交。
<input type="submit" name="submit" class="btn" value="Submit" onClick="return myclick()" />
function myclick()
{
if(document.getElementById('textfield').value == "")
{
alert("Please upload a file or draw one first!");
return false;
}
else
{return true;}
}
一是,在function里直接调用到action。
function goTo() {
var val = document.getElementById("name").value;
document.location.href = "goToAction.do?val=" + val;
}
其他,jsp页面css那些内容:
1.上网下的代码,不需要的功能,删除,但是可能会有默认值之类的东西,那么,就用个div包起来,设置div不可见!<div style="visibility:hidden">
2.居中<center></center>
3.设置模块
<style type="text/css">
a:link {color: blue} /* 未访问的链接 */
a:visited {color: blue} /* 已访问的链接 */
.d1 {background-color:blue}
.btn{ background-color:#FFF; border:1px solid #CDCDCD;height:24px; width:70px;}
.file{ position:absolute; top:0; right:80px; height:24px; filter:alpha(opacity:0);opacity: 0;width:260px }
</style>
然后设置class=...例:<div style="height:4px" class="d1">
附上struts-config.xml的例子:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans />
<global-exceptions />
<global-forwards>
<forward name="index" path="/index.jsp"></forward>
<forward name="result" path="/result.jsp"></forward>
<forward name="nullresult" path="/nullresult.jsp"></forward>
<forward name="detail" path="/detail.jsp"></forward>
</global-forwards>
<action-mappings >
<action path="/imageSearch" type="myaction.ImageSearchAction">
<set-property property="cancellable" value="true" />
</action>
<action path="/show" type="myaction.ShowAction">
<set-property property="cancellable" value="true" />
</action>
<action path="/detail" type="myaction.DetailAction">
<set-property property="cancellable" value="true" />
</action>
</action-mappings>
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>