Tag: url

java中的url编码?

我想知道什么是url编码 。 我有2个jsp页面和一个servlet。 当我运行应用程序时,显示的URL是: http://localhost:8080/myproject/index.jsp 哪里 index.jsp: 单击提交按钮后,显示的URL为: http://localhost:8080/myproject/Myservlet URL编码是什么意思? 我该如何编码url? 从index.jsp转到Myservlet然后转到Myservlet Myservet #doPost //我需要在这里进行URL编码吗? 如果有,怎么样? fetching data from db……. ……………….. String nextJSP = “/result.jsp”; RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); dispatcher.forward(request,response); result.jsp中 displays data here

有没有其他方式来显示url图像?

public class ImageDownloader extends AsyncTask { Context context; ImageView image; public ImageDownloader(ImageView image) { this.image = image; } protected void onPreExecute() { } protected Drawable doInBackground(String… urls) { InputStream is; Drawable d = null ; try { is = (InputStream)new URL(urls[0]).getContent(); d = Drawable.createFromStream(is, “Image”); return d; } catch (MalformedURLException e) { // TODO Auto-generated […]

如何防止openConnection()实际连接

我想使用HttpURLConnection连接到我的webservice,POST一个XML并获得结果。 我使用以下代码: URL url = new URL(urlString); connection = (HttpURLConnection)url.openConnection(); connection.setRequestProperty(“Content-Type”, “text/xml; charset=utf-8”); 问题是,当我调用setRequestProperty方法时,它失败并出现IllegalStateException说我“已经连接”了。 显然, openConnection实际上打开了与URL的连接(在我的调试器中,我可以看到connected布尔值设置为true )。 根据Oracle的URL文档,它不应该。 Android文档尚不清楚。 如何阻止openConnection连接,以便我可以设置额外的属性? 更新看起来connection在某个池中并且不会断开连接,甚至在调用connection.disconnect() ,甚至不会杀死服务器。 我认为这不是这个问题的重复,因为它没有给出真正的答案。 此外,文件似乎不清楚。

java.io.FileNotFoundException在文件名中检索带有变音符号的URL时

我试图在文件名中检索带有变音符号的URL,例如“ http://somesimpledomain.com/some/path/überfile.txt ”,但它给了我一个java.io.FileNotFoundException。 我怀疑远程服务器上的文件名是用latin1编码的,尽管我的url是在utf8中。 但我尝试更改url的编码并不成功,我不知道如何进一步调试它。 请帮忙! 代码如下: HttpURLConnection conn = null; try { conn = (HttpURLConnection) new URL(uri).openConnection(); conn.setRequestMethod(“GET”); } catch (MalformedURLException ex) {} } catch (IOException ex){} // Filter headers int i=1; String hKey; while ((hKey = conn.getHeaderFieldKey(i)) != null) { conn.getHeaderField(i); i++; } // Open the file and output streams InputStream in = […]

如何知道链接将被重定向

我遇到了这种类型的问题 – 当我尝试下载某些网站的favicon时,您会遇到重定向(例如google.com / favicon.ico – > www.google.com / favicon.ico)。 在这种情况下,我的代码不保存图像。 我想知道是否可以知道页面是否被重定向,或者如何更改我的代码以解决这个障碍。 我希望得到你的帮助。 @Override protected Boolean doInBackground(Void…param) { Log.d(“url in NetworkTask”, url); HttpGet httpGet = new HttpGet(url); AndroidHttpClient httpClient = AndroidHttpClient .newInstance(“Android”); HttpResponse httpResponse = null; try { httpResponse = httpClient.execute(httpGet); } catch (IOException e) { e.printStackTrace(); } if(httpResponse!=null) primaryCodeStatus = httpResponse.getStatusLine() .getStatusCode(); else Log.d(“httpResponse”, […]

使用URL或文件(在ImageIO.read中)

我制作了一个使用多个图像的应用程序。 我有2种方式来运行我的应用程序: – 按想法run – 制作一个胖jar文件并从控制台java -jar app.jar运行它 如果我想从Idea运行它我必须使用: BufferedImage backgroundImage = ImageIO.read(new File(“res/field.png”)); 代替 BufferedImage backgroundImage = ImageIO.read(getClass().getClassLoader().getResource(“res/field.png”)); < – 这就是我在jar文件中使用的情况 为什么? 我以为他们差不多了。 我的案子有通用的方法吗?

将Cookie从Java传递到浏览器

我一直在尝试将HttpsURLConnection中的cookie传递给我的浏览器。 不幸的是,我还没有找到…嗯,除了Android之外的任何关于这个主题的东西,这不是我想要的。 Cookie是特定于会话的,因此我每次都必须从网页下载它们。 有没有办法在浏览器(Firefox,Chrome等)中从Java打开网页并发送cookie? 到目前为止的代码:(是的,我知道在主方法上放置“throws Exception”在任何方面都不聪明。请忽略它,当它工作时它不会存在。) public static void main(String[] args) throws Exception { String httpsURL = “https://www.link.com”; URL myurl = new URL(httpsURL); HttpsURLConnection con; CookieManager cManager = new CookieManager(); CookieHandler.setDefault(cManager); /* Start by connecting to website so CookieManager can grab cookies */ con = (HttpsURLConnection) myurl.openConnection(); /*COOKIES*/ CookieStore cookieJar = cManager.getCookieStore(); List cookies = […]

使用Java从URL获取声音

我正在学习英语,我想开发一个软件来帮助我发音。 有一个名为HowJSay的网站,如果你进入这里: http : //www.howjsay.com/index.php ?word = car immediatly你会听到汽车这个词的发音。 我想开发一个JAVA软件,可以播放这个声音,而无需进入网站=] 我试过这个,但不起作用= / public static void main(String[] args) throws Exception { URL url = new URL(“http://www.howjsay.com/index.php?word=car”); url.openConnection(); AudioStream as = new AudioStream(url.openStream()); AudioPlayer.player.start(as); AudioPlayer.player.stop(as); } 有任何想法吗? 请。

从Java下载HTTPS URL中的图像

我必须做一个显示药物包装图像的应用程序。 我发现这个网站有一些,但我试图用Java中的一个小程序下载可用的图像但是失败了。 我认为HTTPS会导致问题。 有办法吗? 编辑:代码和错误 public class DescargarArchivo { public static void main(String[] args) { String url = “http://sofzh.miximages.com/java/visorCaratulas.aspxcod=672629; String name = test.jpg”; String folder = “downloads/”; File dir = new File(folder); if (!dir.exists()) if (!dir.mkdir()) return; File file = new File(folder + name); try { URLConnection conn = new URL(url).openConnection(); conn.connect(); System.out.println(“\ndownload: \n”); System.out.println(“>> […]

在使用Spring MVC和Spring Security @PreAuthorize注释时,是否可以知道URL是否可访问?

在我们的Web项目中,我们使用的是Spring security 3.2.3.RELEASE和Spring MVC(以及其他Spring的东西)4.0.5.RELEASE。 我们的控制器方法注释如下: @RequestMapping(value = “/register”, method = RequestMethod.GET) @PreAuthorize(“hasRole(‘ROLE_MANAGER’)”) public String register() { 我的问题是,如果我的用户可以打电话,我是否可以提出弹簧安全问题 http://localhost:8080/project/register 主要目标是在呈现URL之前开发一个要调用的元数据,这样如果用户无法访问此URL,系统就不会呈现它。 我用JSF和Spring Security开发了类似的方法: @Autowired private WebInvocationPrivilegeEvaluator webInvocationPrivilegeEvaluator; public boolean allowedForAction(String action) { log.debug(“Checking action/url:” + action); Authentication a = SecurityContextHolder.getContext().getAuthentication(); NavigationCase nc = ((ReloadAfterNavigationFix) FacesContext.getCurrentInstance().getApplication() .getNavigationHandler()).getNavigationCase(FacesContext.getCurrentInstance(), null, action); if (nc != null) { return webInvocationPrivilegeEvaluator.isAllowed(nc.getToViewId(FacesContext.getCurrentInstance()), a); } […]