Java replaceAll()正则表达式不起作用

我正在尝试用“%”替换所有特殊字符,例如: “123.456/789” -> “123%465%798” 我的正则表达式是: [^a-zA-Z0-9]+ 在在线工具*它完美地工作,但在java中 s.replaceAll(“[^a-zA-Z0-9]+”, “%”); 字符串保持不变。 *我试过: http : //www.regexplanet.com/ http://regex101.com/和其他人

Spring MVC Mapping问题

我有我认为是一个简单的Spring MVC应用程序。 但是,我似乎可以正确设置requestMappings。 奇怪的是,日志显示url被映射到适当的控制器,但Dispatcher似乎无法在运行时找到它。 我们欢迎所有的建议: 日志 INFO: Mapped URL path [/app/index] onto handler [com.noisyair.whatisayis.web.MainController@420a52f] Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/app/index.*] onto handler [com.noisyair.whatisayis.web.MainController@420a52f] Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/app/index/] onto handler [com.noisyair.whatisayis.web.MainController@420a52f] Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path […]

如何创建.INI文件以在Java中存储一些设置?

我想创建一个ini文件来存储我的应用程序的一些设置。 找到jar文件的位置并在那里创建一个ini文件是一个好主意吗? 如果是,那我怎样才能找到jar文件的位置? 但如果你知道更好的解决方案,我希望听到其中的一些。 编辑 :我正在使用mac,我想在Windows中运行相同的应用程序。 我可以在System.getProperty(“user.home”)目录中写一些东西,但是如果用户决定删除应用程序,我想保持系统清洁。 没有更好的方法来存储设置文件,例如与应用程序在同一目录中?

JTable中的JSpinner(时间)

我正试图在JTable中实现一个JSpinner,它在第一次看起来很有效但在失去了单元格的焦点之后,编辑的单元格被设置为“Thu Jan 01 + time + UTC 1970”时间正在设置正确。 如何从时间中删除日期? 这是我的洞SpinnerEditor.class,添加了一些评论。 代码: public SpinnerEditor(String timeFormat) { super(new JTextField()); // Default Time I want to Display (1 Hour) Time date = new Time(3600000); SpinnerDateModel timeModel = new SpinnerDateModel(date, null, null,Calendar.MINUTE); spinner = new JSpinner(timeModel); editorDate = new JSpinner.DateEditor(spinner, timeFormat); spinner.setEditor(editorDate); editorDate = ((JSpinner.DateEditor)spinner.getEditor()); // println result : […]

尝试findViewById时抛出Nullpointerexception

我有以下活动: public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.container, new StartFragment()) .commit(); } Button login = (Button) findViewById(R.id.loginButton); login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(MainActivity.this,LoginActivity.class); startActivity(intent); } }); } 当我尝试为R.id.loginButton调用findViewByID时,我得到一个NPE,我猜这是因为loginButton在一个单独的片段中,我有: public static class StartFragment extends […]

如何在JSP EL中检查会话?

如何检查EL中的请求是否存在会话? 我正在尝试这样的事情: … 但似乎它永远不会是空的。

Java Array独特的随机生成的整数

public static int[] uniqueRandomElements (int size) { int[] a = new int[size]; for (int i = 0; i < size; i++) { a[i] = (int)(Math.random()*10); for (int j = 0; j < i; j++) { if (a[i] == a[j]) { a[j] = (int)(Math.random()*10); } } } for (int i = 0; i < a.length; i++) […]

在jframe中模糊背景上创建一个透明的矩形

我在模糊背景上创建透明矩形时遇到问题。 我正在尝试在glasspane上完成这项任务。 这是我的代码片段。 void createBlur() { alpha = 1.0f; JRootPane root = SwingUtilities.getRootPane(jf); blurBuffer = GraphicsUtilities.createCompatibleImage(jf.getWidth(), jf.getHeight()); Graphics2D g2d = blurBuffer.createGraphics(); root.paint(g2d); g2d.dispose(); backBuffer = blurBuffer; blurBuffer = GraphicsUtilities.createThumbnailFast(blurBuffer, jf.getWidth() / 2); blurBuffer = new GaussianBlurFilter(5).filter(blurBuffer, null); } 其中,backBuffer和blurBuffer是BufferedImage和jf = JFrame的对象,alpha用于不透明度。 上述方法很好地创建了模糊效果。 这是在Panel上创建透明矩形的代码 protected void paintComponent(Graphics g) { int x = 34; int y = […]

Java – 读取XML文件

我试图从XML文件中读取一些数据并遇到一些麻烦,我的XML如下: test@test.com test2@test.com Sales Query email body message 我试图将这些值作为字符串读入我的Java程序,到目前为止我已编写此代码: private static Document getDocument (String filename){ try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); factory.setValidating(false); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(filename)); } catch (Exception e){ System.out.println(“Error reading configuration file:”); System.out.println(e.getMessage()); } return null; } Document doc = getDocument(configFileName); Element config = doc.getDocumentElement(); 我正在努力阅读实际的字符串值。

方法调用Java类

我今天开始在Eclipse中编写一段代码,我开始是这样的: public class MyClass { System.currentTimeMillis(); } (忽略我不是直接思考等事实……) 我得到这个编译错误: 令牌“currentTimeMillis”上的语法错误,此令牌后预期的标识符 如果我将该语句更改为赋值语句,它可以工作: long time = System.currentTimeMillis(); 当然,如果放在方法体内并且也放在类体内的块内,它不会导致错误。 为什么是这样? 是否有一些编译器级规则表明只有赋值语句或声明应存在于类体内? TIA