我正在尝试为用户登录的每个用户名创建一个文件夹.目前我有
private String destination = "C:/Users/Richard/printing~subversion/fileupload/web/WEB-INF/uploaded/"; // main location for uploads
File theFile = new File(destination + username); // will create a sub folder for each user
Run Code Online (Sandbox Code Playgroud)
但该File theFile
位不会为用户名创建新文件夹.我该怎么做?
我试过了
private String destination;
public void File()
{
destination = "C:/Users/Richard/printing~subversion/fileupload/web/WEB-INF/uploaded/"; // main location for uploads
File theFile = new File(destination + username); // will create a sub folder for each user (currently does not work, below hopefully is a solution)
theFile.mkdirs();
}
Run Code Online (Sandbox Code Playgroud)
但我需要稍后在程序中使用目的地,我该怎么做?
这是我的全部代码:
/*
* To change …
Run Code Online (Sandbox Code Playgroud) 在我的托管bean中,我希望将j_security_check
用户名作为bean属性获取,该用户名将作为LDAP服务器进行身份验证.
基本上,我想从中提取用户名
<input type="text" name="j_username" />
Run Code Online (Sandbox Code Playgroud)
一旦它被提交并且所有authed并在下面使用它:
@Override
public String getName() {
return getId();
}
Run Code Online (Sandbox Code Playgroud)
我该怎么用
FacesContext.getExternalContext().getUserPrincipal();
Run Code Online (Sandbox Code Playgroud)
获取用户名作为bean属性?
如果您需要知道正在做什么,这是完整的支持bean.我曾经手动让用户在文本框中输入用户名,我现在要停止这个并让它自动拉出用户名.
//@Named("user")
@SessionScoped
public class UserBean implements Serializable, Principal {
private static final long serialVersionUID = 1L;
@NotNull(message = "The username can not be blank")
@Size(min = 6, max = 12, message = "Please enter a valid username (6-12 characters)")
//@Pattern(regexp = "[a-zA-Z0-9_]", message = "Please enter a valid username consiting of only characters that are from the alphabet or …
Run Code Online (Sandbox Code Playgroud) 我在我的代码中收到NullPointerException错误,我已将其缩小为导致异常的这段代码
AttributedString mStyledText = new AttributedString(mText);
Run Code Online (Sandbox Code Playgroud)
我原以为mText的值将使用以下代码从代码中进一步恢复:
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(path));
List<String> list = new ArrayList<String>();
while ((mText = br.readLine()) != null) {
//Displays the contents of the file in terminal
System.out.println(mText);
list.add(mText);
}
Run Code Online (Sandbox Code Playgroud)
但我仍然得到null错误,我认为mText的值将来自上面的代码并被使用,但这似乎没有发生,为什么这样,整个代码在下面
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.print.*;
import java.text.*;
import java.io.*;
import javax.swing.*;
import java.util.List;
import java.util.ArrayList;
public class PrintText implements Printable {
private List<String> list;
// Below the code will allow the user to select a …
Run Code Online (Sandbox Code Playgroud) 我一直在努力保护我的项目.我有一个登录页面,使用LDAP服务器进行身份验证,如果不正确,则会启动错误页面等.我现在刚刚添加了
<auth-constraint> <!-- Currently causing a 403, looks like stoping .css files -->
<role-name>*</role-name>
</auth-constraint>
Run Code Online (Sandbox Code Playgroud)
到我的web.xml,以确保用户在查看任何页面之前都经过身份验证,但是它似乎阻止了我的.css文件,我想现在登录页面根本没有显示任何css,只是白色基本的,当我按提交时,我得到:
有这个错误:
HTTP状态403 - 拒绝访问所请求的资源
类型状态报告
消息已拒绝访问所请求的资源
说明已禁止访问指定的资源(已拒绝访问所请求的资源).
GlassFish Server开源版3.1.2.2
这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>Upload Filter</filter-name>
<filter-class>richard.fileupload.UploadFilter</filter-class>
<init-param>
<param-name>sizeThreshold</param-name>
<param-value>1024</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Upload Filter</filter-name>
<url-pattern>/upload/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>facelets.LIBRARIES</param-name> …
Run Code Online (Sandbox Code Playgroud) 嗨伙计们我在JSF中有一个数据表,显示我的数据库表的所有内容,它显示它很好,我还有一个删除功能,可以成功从数据库中删除并更新数据表罚款,但是当我尝试更新数据库我得到错误
java.lang.IllegalArgumentException: Cannot convert richard.test.User@129d62a7 of type class richard.test.User to long
Run Code Online (Sandbox Code Playgroud)
下面是我用来删除数据库中正常工作的行的代码:
public void delete(long userID) {
PreparedStatement ps = null;
Connection con = null;
if (userID != 0) {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
String sql = "DELETE FROM user1 WHERE userId=" + userID;
ps = con.prepareStatement(sql);
int i = ps.executeUpdate();
if (i > 0) {
System.out.println("Row deleted successfully");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
con.close();
ps.close();
} catch (Exception …
Run Code Online (Sandbox Code Playgroud) 大家好,我被要求将旧的Java EE Web应用程序(JSP/Servlet,EJB,JPA)转换为一个现代的JSF应用程序,除了servlet之外我做的最多,
当前的servlet是:
@WebServlet(name = "StudentServlet", urlPatterns = {"/StudentServlet"})
public class StudentServlet extends HttpServlet {
@EJB
private StudentDaoLocal studentDao;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter("action");
String studentIdStr = request.getParameter("studentId");
int studentId=0;
if(studentIdStr!=null && !studentIdStr.equals("")){
studentId=Integer.parseInt(studentIdStr);
}
String firstname = request.getParameter("firstname");
String lastname = request.getParameter("lastname");
String yearLevelStr = request.getParameter("yearLevel");
int yearLevel=0;
if(yearLevelStr!=null && !yearLevelStr.equals("")){
yearLevel=Integer.parseInt(yearLevelStr);
}
Student student = new Student(studentId, firstname, lastname, yearLevel);
if("Add".equalsIgnoreCase(action)){
studentDao.addStudent(student);
}else if("Edit".equalsIgnoreCase(action)){
studentDao.editStudent(student);
}else if("Delete".equalsIgnoreCase(action)){
studentDao.deleteStudent(studentId); …
Run Code Online (Sandbox Code Playgroud)