以下代码:
<?php
class Type {
}
function foo(Type $t) {
}
foo(null);
?>
Run Code Online (Sandbox Code Playgroud)
在运行时失败:
PHP Fatal error: Argument 1 passed to foo() must not be null
Run Code Online (Sandbox Code Playgroud)
为什么不允许像其他语言一样传递null?
我正在尝试上传ajax文件.我读到如果不使用它就不可能做到这一点iframe.
我写 :
<iframe id="uploadTrg" name="uploadTrg" height="0" width="0" frameborder="0" scrolling="yes"></iframe>
<form id="myForm" action="file-component" method="post" enctype="multipart/form-data" target="uploadTrg">
File: <input type="file" name="file">
<input type="submit" value="Submit" id="submitBtn"/>
</form>
Run Code Online (Sandbox Code Playgroud)
并使用jquery表单插件:
$('#myForm').ajaxForm({
dataType: 'json',
success: function(data){
alert(data.toSource());
}
});
Run Code Online (Sandbox Code Playgroud)
结果 :
文件上传成功,我可以看到上传的文件,但会出现一个对话框:
因为我发回一个json结果来显示文件名+大小等.
我的问题: 如何使用iFrame进行"ajax文件上传".
注意:
谢谢
我有一个有偏好活动language作为ListPreference其显示可用的语言列表.我可以在调用onCreate时填充列表,但是当用户点击它时我想填写列表.
this is the java code :
public class SettingsActivity extends PreferenceActivity implements OnPreferenceClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
addPreferencesFromResource(R.xml.settings);
} catch (Exception e) {
}
}
@Override
public boolean onPreferenceClick(Preference preference) {
if((preference instanceof ListPreference) && (preference.getKey().equals("language"))){
ListPreference lp = (ListPreference)preference;
CharSequence[] entries = { "English", "French" };
CharSequence[] entryValues = {"1" , "2"};
lp.setEntries(entries);
lp.setDefaultValue("1");
lp.setEntryValues(entryValues);
return true;
}
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
这是settings.xml(偏好):
<?xml version="1.0" encoding="utf-8"?> …Run Code Online (Sandbox Code Playgroud) 在CSS上我们可以写:
<div style="float:right"> Text1 </div>
<div style="float:right"> Text2 </div>
Run Code Online (Sandbox Code Playgroud)
通过这种方式Text1将出现在右边..
我试图对LinearLayout做同样的事情,View应该从右到左显示:
<LinearLayout android:id="@+id/linearLayout1" android:layout_gravity="right" android:gravity="right"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:weightSum="2" android:orientation="horizontal">
<!-- First Column should be on the right : Text1-->
<LinearLayout android:id="@+id/linearLayout2"
android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="right" android:gravity="right"
android:layout_weight="1">...</LinearLayout>
<!-- Second Column should be on the left : Text2 -->
<LinearLayout android:id="@+id/linearLayout3"
android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="right" android:gravity="right"
android:layout_weight="1">...</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在开发一个JSP/Servlet Web应用程序(没有框架).我想使用MVC模式.我打算像这样设计我的项目:
问题: Index.jsp是我网站的起点(默认页面).因此,Index.jsp成为解析请求的控制器.例如,以下请求:
index.jsp?section=article&id=10
Run Code Online (Sandbox Code Playgroud)
在index.jsp中解析如下:
<div class="midcol">
<!-- Which section? -->
<%String fileName = request.getParameter("section");
if (fileName == null) {
fileName = "WEB-INF/jspf/frontpage.jsp";
} else {
fileName = "WEB-INF/jspf/" + fileName + ".jsp";
}
%>
<jsp:include page='<%= fileName%>' />
</div>
Run Code Online (Sandbox Code Playgroud)
在这里,我不能强制servlet成为一个控制器,因为这index.jsp是控制器,因为它是起点.
是否有任何解决方案将请求转发index.jsp到servlet然后返回index.jsp?或任何实现MVC目标的解决方案- servlet应该是控制器?
我正在考虑将FrontPageController servlet作为默认页面而不是index.jsp,但我不知道它是否是一个完美的主意?
在任何编程语言中,我都可以跟踪任何函数并知道其他函数调用了哪个函数.但是在Javascript中,我不知道如何,因为代码不是由我编写的,而且Firebug没有提供此功能 - 据我所知.
一个例子 :
我想显示单击XYZ元素时调用的每个函数的函数名称,并按顺序显示它们.
谢谢.
我想为此xml文档创建DTD架构:
<root>
<student>
<name>
<firstname>S1</firstname>
<lastname>S2</lastname>
</name>
</student>
<course>
<name>CS101</name>
</course>
</root>
Run Code Online (Sandbox Code Playgroud)
你可以看到,该元素name在course包含纯文本,但该元素name的student复杂类型(第一姓,名).以下是DTD:
<!ELEMENT root (course|student)*>
<!ELEMENT student (name)>
<!ELEMENT name (lastname|firstname)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT course (name)>
Run Code Online (Sandbox Code Playgroud)
当我想验证它时,我得到一个错误,因为该课程的name结构与学生的结构不同name.
我的问题:
name使用DTD而不是xml架构更改元素名称的情况下为此情况制定解决方案.谢谢.
我有一个简单的jsp/servlet应用程序,我想为这个应用程序添加AJAX功能.我使用JQuery,但我使用的javascript框架并不重要.这是我的代码:
<script type="text/javascript">
function callbackFunction(data){
$('#content').html(data);
}
$('document').ready(function(){
$('#x').click(function() {
$.post('/ajax_2/servlet',callbackFunction)
});
});
</script>
<body>
<a href="#" id="x">Increase it</a>
<div id="content"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Servlet的
HttpSession session = request.getSession();
Integer myInteger = (Integer)session.getAttribute("myInteger");
if(myInteger == null)
myInteger = new Integer(0);
else
myInteger = new Integer(myInteger+1);
session.setAttribute("myInteger", myInteger);
response.getWriter().println(myInteger);
Run Code Online (Sandbox Code Playgroud)
问题:
我使用out.print将数据从servlet传输到javascript代码(ajax代码),但是如果我有一个复杂的结构,比如Vector of Objects或类似的东西,那么传输数据的最佳方法是什么?怎么样的XML文件,JSON?是否有任何特殊的 jsp/servlets库将数据从servlet传输到ajax应用程序?如何在callbackFunction中解析这些数据?
我正在尝试在用户按下发送按钮时更改Outlook中"发送至"字段中的电子邮件地址.例如,如果当前Item.To值= 'aaa@example.com'它变为'bbb@example.com'.
我可以改变主题,但是没有使用Item.To(是安全问题吗?):
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If Item.Class <> olMail Then Exit Sub
Item.To = "bbb@example.com" ' Nope , It does not work
Item.Subject = "New Subject" ' It works
End Sub
Run Code Online (Sandbox Code Playgroud)
谢谢
如果应用程序发现用户未经过身份验证/授权执行某项操作,那是否是意外情况?
try {
if (notAuth())
throw new UnAuthException();
} catch (UnAuthException e) {
Log . error(e);
return false;
}
Run Code Online (Sandbox Code Playgroud)
如果是预期的情况,那么为什么有这么多的框架有自己的UnAuthException如果失败的Auth不是例外?
servlets ×3
ajax ×2
android ×2
jquery ×2
jsp ×2
css-float ×1
dtd ×1
exception ×1
file-upload ×1
javascript ×1
outlook ×1
outlook-vba ×1
php ×1
type-hinting ×1
vba ×1
xml ×1
xsd ×1