在我的网络应用程序中,我使用jQuery的$.getJSON()方法提交了一些表单字段.我在编码方面遇到了一些问题.我的应用程序的字符集是charset=ISO-8859-1,但我认为这些字段是提交的UTF-8.
如何设置$.getJSON调用中使用的编码?
有没有一种简单的方法可以使用JAVA将HTML转换为markdown?
我目前正在使用Java MarkdownJ库将markdown转换为html.
import com.petebevin.markdown.MarkdownProcessor;
...
public static String getHTML(String markdown) {
MarkdownProcessor markdown_processor = new MarkdownProcessor();
return markdown_processor.markdown(markdown);
}
public static String getMarkdown(String html) {
/* TODO Ask stackoverflow */
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试格式化日期:
<fmt:formatDate value="${newsletter.createdOn}" pattern="MM/dd/yyyy"/>
Run Code Online (Sandbox Code Playgroud)
时事通讯是一个createdOn有财产的对象java.util.Date.
当我调用上一句时,我得到:
根据TLD,属性值不接受表达式.
我正在导入fmt
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?
我正在使用与tomcat一起使用的jstl.jar.
在jstl.jar/META-INF/MANIFEST.MF下保留:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.5.3
Created-By: 1.4.2-b28 (Sun Microsystems Inc.)
Specification-Title: JavaServer Pages Standard Tag Library (JSTL)
Specification-Version: 1.1
Implementation-Title: JavaServer Pages Standard Tag Library API Refere
nce Implementation
Implementation-Version: 1.1.0-D13
Implementation-Vendor: Sun Microsystems, Inc.
Implementation-Vendor-Id: com.sun
Extension-Name: javax.servlet.jsp.jstl
Run Code Online (Sandbox Code Playgroud)
我正在使用Apache Tomcat版本6.0.14
在我看来phpMyAdmin默认导入表格与排序latin1_swedish_ci,我怎么改变这个?
我收到了下一个JSON响应
{
"timetables":[
{"id":87,"content":"B","language":"English","code":"en"},
{"id":87,"content":"a","language":"Castellano","code":"es"}],
"id":6,
"address":"C/Maestro José"
}
Run Code Online (Sandbox Code Playgroud)
我想实现下一个伪代码功能
for(var i in json) {
if(json[i] is Array) {
// Iterate the array and do stuff
} else {
// Do another thing
}
}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我有一个Java数组,如:
String[] arr = new String[] {"123","doc","projectReport.doc"};
Run Code Online (Sandbox Code Playgroud)
在我看来,访问的自然方式是:
#set($att_id = $arr[0])
#set($att_type = $arr[1])
#set($att_name = $arr[2])
Run Code Online (Sandbox Code Playgroud)
但它没有用.我已经采用了这种解决方法.但是对于这么简单的任务来说,它的代码太多了.
#set($counter = 0)
#foreach($el in $arr)
#if($counter==0)
#set($att_id = $el)
#elseif($counter==1)
#set($att_type = $el)
#elseif($counter==2)
#set($att_name = $el)
#end
#set($counter = $counter + 1)
#end
Run Code Online (Sandbox Code Playgroud)
还有其他方法吗?
我在使用Ajax提交包含UTF-8字符串的表单时遇到问题.我正在开发一个在Tomcat服务器上运行的Struts Web应用程序.这是我设置为使用UTF-8的环境:
我已经添加的属性URIEncoding="UTF-8" useBodyEncodingForURI="true"到Connector标签到Tomcat的conf/server.xml文件.
我有一个utf-8_general_ci数据库
我正在使用下一个过滤器来确保我的请求和响应以UTF-8编码
package filters;
import java.io.IOException;
import javax.servlet.*;
public class UTF8Filter implements Filter {
public void destroy() {}
public void doFilter(ServletRequest request,ServletResponse response, FilterChain chain)
throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
}
}
Run Code Online (Sandbox Code Playgroud)我在WEB-INF/web.xml中使用此过滤器
我正在使用我的JSON响应的下一个代码:
public static void populateWithJSON(HttpServletResponse response,JSONObject json)
{
String CONTENT_TYPE="text/x-json;charset=UTF-8";
response.setContentType(CONTENT_TYPE);
response.setHeader("Cache-Control", "no-cache");
try {
response.getWriter().write(json.toString());
} catch (IOException e) { …Run Code Online (Sandbox Code Playgroud)我正在尝试使用Bill the Lizard的代码来使用Google Apps发送电子邮件.我收到此错误:
Exception in thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. f3sm9277120nfh.74
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:81)
at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:44)
Run Code Online (Sandbox Code Playgroud)
Bill的代码包含下一行,它似乎与错误有关:
props.put("mail.smtp.starttls.enable","true");
Run Code Online (Sandbox Code Playgroud)
但是,它没有帮助.
这些是我的导入声明:
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
Run Code Online (Sandbox Code Playgroud)
有谁知道这个错误?
我正在使用下一个类(为了便于理解而简化)在struts web应用程序中下载图像.它在每个浏览器中运行良好,但firefox,它切割包含空格的名称.这就是说:带有spaces.pdf的文件在firefox中下载为:file,而在chrome中,IE7 IE6作为文件下载到spaces.pdf.
public class Download extends Action {
private static final int BUFFER_SIZE = 4096;
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
String filename = "file with spaces.pdf";
File file = ... // variable containing the file;
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType(getMimeType(request, file));
response.setHeader("Content-Type", getMimeType(request, file));
response.setHeader("Content-Disposition","attachment; filename="+ filename);
InputStream is = new FileInputStream(file);
sendFile(is, response);
return null;
}
protected String getMimeType(HttpServletRequest request, File file) {
ServletContext application …Run Code Online (Sandbox Code Playgroud) 我想根据当前Locale的值包含一个js文件.我试图从JSP访问它如下:
<%@ page import="java.util.Locale" %>
<% if( ((Locale) pageContext.getAttribute("org.apache.struts.action.LOCALE",PageContext.REQUEST_SCOPE)).getLanguage().equals("de")) { %>
<script src="../themes/administration/js/languages/i18nDE.js" type="text/javascript"> </script>
<% } else { %>
<script src="../themes/administration/js/languages/i18nEN.js" type="text/javascript"> </script>
<% } %>
Run Code Online (Sandbox Code Playgroud)
但是,我得到一个java.lang.NullPointerException,因为 pageContext.getAttribute("org.apache.struts.action.LOCALE",PageContext.REQUEST_SCOPE)是NULL.
有谁知道我怎么能解决这个问题?